Skip to content

feat: add end-to-end tests for sqlcmd binary (fixes #641)#642

Merged
dlevy-msft-sql merged 2 commits intomicrosoft:mainfrom
dlevy-msft-sql:feature/e2e-tests-641
Jan 27, 2026
Merged

feat: add end-to-end tests for sqlcmd binary (fixes #641)#642
dlevy-msft-sql merged 2 commits intomicrosoft:mainfrom
dlevy-msft-sql:feature/e2e-tests-641

Conversation

@dlevy-msft-sql
Copy link
Contributor

@dlevy-msft-sql dlevy-msft-sql commented Jan 27, 2026

Summary

Adds end-to-end tests that build the sqlcmd binary and exercise real-world
scenarios, as suggested by @shueybubbles in PR #640.

Test Cases

Test Description
\TestE2E_Help\ Verifies --help\ flag produces expected output
\TestE2E_Version\ Verifies --version\ flag works
\TestE2E_PipedInput_NoPanic\ Regression test for #607 - piped input with -G\ flag doesn't panic
\TestE2E_PipedInput_EmptyInput\ Empty piped input doesn't cause panic
\TestE2E_InvalidFlag\ Invalid flags produce helpful error messages
\TestE2E_QueryFlag_NoServer\ -Q\ flag without server doesn't panic
\TestE2E_InputFile_NotFound\ Missing input file errors gracefully
\TestE2E_PipedInput_WithBytesBuffer_NoPanic\ GO batches in piped input work correctly

Live Connection Tests (run when SQLCMDSERVER is set)

Test Description
\TestE2E_PipedInput_LiveConnection\ Piped input executes queries successfully
\TestE2E_QueryFlag_LiveConnection\ -Q\ flag executes queries successfully
\TestE2E_InputFile_LiveConnection\ Input file with SQL executes successfully

Implementation Details

  • Binary is built once per test run using \sync.Once\ for efficiency
  • Tests verify error handling and absence of panics, not successful connections
  • Live connection tests skip when SQLCMDSERVER is not set
  • Binary is placed in a temp directory and cleaned up after tests

Related

Testing

\\�ash
go test -v -run TestE2E ./cmd/modern/...
\\

All 11 tests pass locally (8 always run, 3 skip when no live connection).

@dlevy-msft-sql dlevy-msft-sql self-assigned this Jan 27, 2026
@dlevy-msft-sql dlevy-msft-sql added Size: S Small issue (less than one week effort) testing housekeeping and removed housekeeping labels Jan 27, 2026
@dlevy-msft-sql dlevy-msft-sql added this to the v1.9.2 milestone Jan 27, 2026
@shueybubbles
Copy link
Collaborator

these tests should use real queries because we have live connections available in the test pipelines. they can just rely on SQLCMDSERVER being set etc

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive end-to-end tests for the sqlcmd binary that build and execute the actual binary to verify behavior in real-world scenarios. The tests primarily focus on verifying that error conditions (like piped input, missing files, invalid flags) are handled gracefully without panics, especially addressing the regression reported in issue #607.

Changes:

  • Adds 8 e2e tests covering help, version, piped input, invalid flags, query execution, and input file handling
  • Implements a build-once pattern using sync.Once for efficiency across all test cases
  • Uses TestMain for cleanup of the temporary binary after tests complete

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Add e2e tests that build the sqlcmd binary and exercise real-world scenarios:

Non-connection tests (always run):
- TestE2E_Help: verifies --help flag works
- TestE2E_Version: verifies --version flag works
- TestE2E_PipedInput_NoPanic: regression test for microsoft#607 (piped input panic)
- TestE2E_PipedInput_EmptyInput: empty piped input doesn't panic
- TestE2E_InvalidFlag: invalid flags produce helpful errors
- TestE2E_QueryFlag_NoServer: -Q flag without server doesn't panic
- TestE2E_InputFile_NotFound: missing input file errors gracefully
- TestE2E_PipedInput_WithStdinReader: GO batches in piped input work

Live connection tests (run when SQLCMDSERVER is set):
- TestE2E_PipedInput_LiveConnection: piped SQL with real server
- TestE2E_QueryFlag_LiveConnection: -Q flag with real server
- TestE2E_InputFile_LiveConnection: -i flag with real server

The tests build the binary once and reuse it for all tests.
Live connection tests use SQLCMDSERVER, SQLCMDUSER, SQLCMDPASSWORD env vars.

Addresses feedback from @shueybubbles in PR microsoft#640.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@dlevy-msft-sql dlevy-msft-sql merged commit f43706d into microsoft:main Jan 27, 2026
3 checks passed
@dlevy-msft-sql dlevy-msft-sql deleted the feature/e2e-tests-641 branch January 27, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: S Small issue (less than one week effort) testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add end-to-end tests that build and run the sqlcmd binary

3 participants