Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions cmd/modern/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func hasLiveConnection() bool {
return os.Getenv("SQLCMDSERVER") != ""
}

// hasSQLAuthCredentials returns true if SQL authentication credentials are available.
// For Azure AD/Entra authentication methods, we need different handling.
func hasSQLAuthCredentials() bool {
return os.Getenv("SQLCMDUSER") != "" && os.Getenv("SQLCMDPASSWORD") != ""
}

// skipIfNoLiveConnection skips the test if no live SQL Server connection is available.
func skipIfNoLiveConnection(t *testing.T) {
t.Helper()
Expand All @@ -80,6 +86,17 @@ func skipIfNoLiveConnection(t *testing.T) {
}
}

// skipIfNoSQLAuth skips the test if SQL authentication credentials are not available.
// Tests requiring SQL auth should use this instead of skipIfNoLiveConnection when they
// don't support Azure AD/Entra authentication.
func skipIfNoSQLAuth(t *testing.T) {
t.Helper()
skipIfNoLiveConnection(t)
if !hasSQLAuthCredentials() {
t.Skip("Skipping: SQLCMDUSER/SQLCMDPASSWORD not set, SQL auth not available (may be using Azure AD)")
}
}

type buildError struct {
err error
output string
Expand Down Expand Up @@ -143,9 +160,10 @@ func TestE2E_PipedInput_NoPanic(t *testing.T) {
}

// TestE2E_PipedInput_LiveConnection tests piping input with a real SQL Server connection.
// This test only runs when SQLCMDSERVER is set.
// This test only runs when SQLCMDSERVER and SQL auth credentials are set.
// It does not support Azure AD/Entra authentication yet.
func TestE2E_PipedInput_LiveConnection(t *testing.T) {
skipIfNoLiveConnection(t)
skipIfNoSQLAuth(t)
binary := buildBinary(t)

cmd := exec.Command(binary, "-C")
Expand Down Expand Up @@ -208,9 +226,9 @@ func TestE2E_QueryFlag_NoServer(t *testing.T) {
}

// TestE2E_QueryFlag_LiveConnection tests the -Q flag with a real SQL Server connection.
// This test only runs when SQLCMDSERVER is set.
// This test only runs when SQLCMDSERVER and SQL auth credentials are set.
func TestE2E_QueryFlag_LiveConnection(t *testing.T) {
skipIfNoLiveConnection(t)
skipIfNoSQLAuth(t)
binary := buildBinary(t)

cmd := exec.Command(binary, "-C", "-Q", "SELECT 42 AS Answer")
Expand All @@ -237,9 +255,9 @@ func TestE2E_InputFile_NotFound(t *testing.T) {
}

// TestE2E_InputFile_LiveConnection tests the -i flag with a real SQL Server connection.
// This test only runs when SQLCMDSERVER is set.
// This test only runs when SQLCMDSERVER and SQL auth credentials are set.
func TestE2E_InputFile_LiveConnection(t *testing.T) {
skipIfNoLiveConnection(t)
skipIfNoSQLAuth(t)
binary := buildBinary(t)

// Create a temporary SQL file
Expand Down
Loading