refactor: convert Bash integration tests to Go tests#666
Merged
boyter merged 2 commits intoboyter:masterfrom Dec 12, 2025
Merged
refactor: convert Bash integration tests to Go tests#666boyter merged 2 commits intoboyter:masterfrom
boyter merged 2 commits intoboyter:masterfrom
Conversation
f250759 to
fe1a0f9
Compare
fe1a0f9 to
0bacaa9
Compare
Owner
|
Yeah neat. This looks like a good way to start breaking away from that test script into pure Go. Somewhat related to what I started over #633 although this does the main thing I had been putting off. |
Contributor
Author
This PR is ready for review. You can take a look at the converted test cases to check if I missed something. |
Owner
|
Yep on my list, but as the insights bot suggests its a bit one :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
How It Works
Golang compiles all test cases and their related code into a single binary file (usually named as
<package-name>.test). The binary will callfunc TestMain(m *testing.M)before any test case running. So we can call our main function in theTestMainif special flag was set. This will include all SCC code in the generated binary file, transforming it into an SCC command-line program with test cases. Calling this binary file is almost equivalent to directly invoking SCC. Therefore, we can useexec.Commandin our integration test cases to invoke this binary file and capture all its output for our testing.The
TestMainlooks like this:We can use a helper function to run SCC and add special flags:
This makes the test code much simple than what #633 does. Similar strategies are widely used in projects like Kubernetes, Docker, the Go compiler, Prometheus and so on.
Migrating all integration tests is a big project, so I will complete it in several steps:
This PR is the first two step.
Disadvantages:
The runtime of
go test -racehas significantly increased. For comparison, the runtime on my laptop before migration was 10s, while after migration it is 40s. Althought.Parallel()is used to run tests in parallel, the total runtime is expected to exceed one minute once all tests are migrated.