Repository navigation
test: enforce test file stems and remove duplicate error tests - #243
Merged
Merged
Conversation
The test file check groups a subject's tests by platform, but platform() used the whole //go:build expression as the group. A file tagged "linux && integration" got its own group, apart from *_linux_test.go, so a non-platform tag could split a subject's tests without a violation. The same goes for equivalent constraints written differently, such as "amd64 && linux" and *_linux_amd64_test.go. Compare the GOOS/GOARCH pairs a file can build for rather than the text of its constraints. A file name and a constraint that select the same platforms now group together, whatever their order. Tags that don't name a platform don't make a file platform-specific: each setting of them is tried, with one value per tag across the file, so "(linux || integration) && !integration" still counts as Linux. This replaces namesPlatform. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
CONTRIBUTING.md names a subject's files <subject>_test.go, <subject>_errors_test.go, and <subject>_boundary_test.go, but nothing checks that those files share a stem. TestLoad, TestValidateConfig, TestInitLogging, and TestRuntimeHandlePayload each had a bucket in a file named after something else, so a reader who opens the plain test file wouldn't find the rest next to it. Move those tests to files that match, without changing them. Add a check that flags a subject's bucket files with different stems, and describe the rule in CONTRIBUTING.md. The check compares only files for the same platforms, using platform(), and leaves out the error tables across cmd families in commands_errors_test.go, whose plain tests are in a file named after the behavior. Also rename TestBSSHistoryGet_* to TestBSSHistory_*, since "bss history" is a leaf command and there is no "bss history get". Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
The tables in commands_errors_test.go guarantee each command's exit code for a failure. Some per-family error tests ran the same command with the same failure and asserted nothing more than the row, at the cost of a second server and run, and had to be kept in step with the table. Remove the 19 tests that exactly repeat a row, along with bss_boot_script_errors_test.go, which held only one of them. Coverage of cmd, internal/cli, and pkg from the cmd tests is unchanged. Keep the tests that cover more, and record the rule in CONTRIBUTING.md: those with a different selector, flag, or stub response, and those that assert the request, message, or output. The tests for commands with no table row also stay. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
"smd status" and "bss status" hold their own copy of the status logic, so tests of "service status" say nothing about them, and no test asserted their exit codes. Add both to the service command error tables. TestSMDDeprecatedStatus_HTTPError ran "smd service status" rather than the deprecated command, so rename it TestSMDServiceStatus_HTTPError. TestCloudInitNodeGetData_HTTPError repeated TestCloudInitNodeGet_MetadataHTTPError, while "cloud-init node get vendor-data" had no HTTP error test. Point it at vendor-data, and rename it to match the tests of the other data types. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
synackd
force-pushed
the
test/reorganize
branch
from
November 5, 2026 17:07
c4e40d8 to
16b3677
Compare
synackd
marked this pull request as ready for review
November 5, 2026 17:16
davidallendj
self-requested a review
November 10, 2026 19:28
davidallendj
approved these changes
Nov 10, 2026
davidallendj
left a comment
Contributor
There was a problem hiding this comment.
LGTM. I tested this and all tests passed with the exception of the few that deliberately fail due to the changes.
=== RUN TestTestFiles_SubjectInOneFile
conventions_test.go:933: internal/conventions/pr243probe.ZVEw0Z/widget_linux_test.go:11: TestWidget tests (plain) are split between widget_integration_test.go and widget_linux_test.go
conventions_test.go:933: Move the test into its subject's file for that bucket, or give a too-broad subject a more specific name; see CONTRIBUTING.md.
--- FAIL: TestTestFiles_SubjectInOneFile (0.08s)
FAIL
FAIL github.com/openchami/ochami/internal/conventions 0.330s
FAIL=== RUN TestTestFiles_SubjectBucketsShareStem
conventions_test.go:941: pkg/config/pr243_wrong_boundary_test.go:17: TestLoad tests are in loader_errors_test.go and pr243_wrong_boundary_test.go, which have different stems
conventions_test.go:941: Name a subject's bucket files <stem>_test.go, <stem>_errors_test.go, and <stem>_boundary_test.go. See CONTRIBUTING.md.
--- FAIL: TestTestFiles_SubjectBucketsShareStem (0.08s)
FAIL
FAIL github.com/openchami/ochami/internal/conventions 0.746s
FAIL
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.
Description
Fixes #232
Fixes #235
Fixes #236
Summary
These are the follow-ups to the test layout work in #218. They close a gap in the one-file-per-subject check, add a check that a subject's bucket files share a stem, and remove per-family error tests that repeat a row of a command-wide table. The change touches only tests, test fixtures, and
CONTRIBUTING.md, so it needs no changelog entry.The commits are meant to be reviewed one at a time. Each one passes
make lint reuse mod test.Changes
#232:
test: ignore non-platform tags in subject groupingplatform()used the whole//go:buildexpression as a grouping key, so a file taggedlinux && integrationgot its own group and could split a subject's tests. It now compares the GOOS/GOARCH pairs a file can build for, rather than the text of its constraints. A file name and a constraint that select the same platforms group together, whatever their order. Tags that don't name a platform don't make a file platform-specific:canBuildtries each setting of them, with one value per tag across the file.canBuild,appendOtherTags, andmatchesPlatformreplacenamesPlatform.This also fixes cases the issue doesn't name:
amd64 && linuxvslinux && amd64,windows_amd64in a file name vswindows && amd64, andlinux || darwinvsdarwin || linux.#235:
test: keep subject bucket files on one stemTestLoad_ClusterShapeBoundaries,TestLoad_AcceptsNullClusterConfigpkg/config/config_boundary_test.gopkg/config/loader_boundary_test.goTestValidateConfig_NullAndShapeBoundariespkg/config/config_boundary_test.gopkg/config/validate_boundary_test.goTestInitLogging_RejectsInvalidConfigurationinternal/cli/runtime_errors_test.gointernal/cli/runtime_logging_errors_test.goTestRuntimeHandlePayload_StdinCancelledinternal/cli/runtime_errors_test.gointernal/cli/runtime_input_environment_errors_test.goEach moved test is byte-identical to
main.TestBSSHistoryGet_*becomesTestBSSHistory_*, sincebss historyis a leaf command.The new
TestTestFiles_SubjectBucketsShareStemflags a subject whose plain,_errors, and_boundaryfiles have different stems. It compares only files for the same platforms, which coversTestWriteFileandTestSyncParentDirectory, and it leaves outcmd/commands_errors_test.go, which coversTestServiceCommands.CONTRIBUTING.mddocuments the rule.#236:
test: remove error tests that repeat table rowsThis removes 19 tests that run the same command with the same failure as a table row and assert nothing beyond the error and exit code.
cmd/bss_boot_script_errors_test.goheld only one of them, so it is deleted.TestServiceCommands_NetworkErrorTestSMDGroupGet_NetworkError,TestSMDCompepGet_NetworkError,TestSMDComponentGet_NetworkError,TestSMDIfaceGet_NetworkError,TestSMDRFEGet_NetworkError,TestBSSBootParamsGet_AllNetworkError,TestCloudInitGroupGet_NetworkErrorTestWriteCommands_NetworkErrorTestSMDGroupAdd_NetworkErrorTestServiceCommands_HTTPErrorTestSMDGroupGet_HTTPError,TestSMDCompepGet_AllHTTPError,TestSMDComponentGet_AllHTTPError,TestSMDIfaceGet_HTTPError,TestSMDRFEGet_HTTPError,TestBSSBootParamsGet_AllHTTPError,TestBSSBootScriptGet_HTTPError,TestCloudInitGroupGet_HTTPError,TestPCSTransitionList_HTTPErrorTestCommands_MalformedPayloadTestCloudInitGroupAdd_MalformedPayload,TestCloudInitNodeSet_MalformedPayloadThe policy is now in the "Command tests" section of
CONTRIBUTING.md: a per-family error test stays when it uses a different selector, flag, or stub response than its row, or asserts more than the exit code.Beyond the issues:
test: cover deprecated status and vendor-data errorsAuditing #236 turned up three related problems, fixed here:
TestSMDDeprecatedStatus_HTTPErrorransmd service status, not the deprecated command, so it is nowTestSMDServiceStatus_HTTPError.smd statusandbss statushold their own copy of the status logic, and no test asserted their exit codes. Both now have rows inTestServiceCommands_NetworkErrorandTestServiceCommands_HTTPError.TestCloudInitNodeGetData_HTTPErrorrepeatedTestCloudInitNodeGet_MetadataHTTPError, whilecloud-init node get vendor-datahad no HTTP error test. It now testsvendor-data, asTestCloudInitNodeGet_VendordataHTTPError.Review notes
TestRuntimeHandlePayloadalso had mismatched stems, because fix: cancel command context on SIGINT and SIGTERM #234 added_StdinCancelledafter the issue was filed. The new check would fail on it, so it moved too._NetworkErrortests, but there are 20, plusTestSMDGroupMember_NetworkErrors. Only 8 of them repeat a row. The rest stay: selector variants (ByXname,ByNID,ByID),discovervariants, and commands with no table row (bss boot paramswrites,bootandmetadatalist,smd group member).TestCloudInitNodeGet_MetadataHTTPErroruses a 404 andTestPCSStatusList_HTTPErroruses a 503, while the table's stub returns 500.clientErrorCodeignores the status today, so they could count as duplicates. They stay in case status-specific behavior appears.testdata/violationsnow has acmd/directory so that the check's path exception is covered by a fixture.Manual testing
The stem script from #235 now prints only the intentional cases:
The rest was checked once by hand:
linux && integrationfixture gave 3 split violations with the oldplatform()and gives 4 now.matchesPlatformagrees withgo/buildon 611 tag and platform combinations fromgo tool dist list, andplatform()matchedgo/buildon 400 random constraints. 95 of those can never build, so they compare nothing.loader_boundary_test.goto a mismatched stem makes the new check fail.cmdtests, across./cmd/...,./internal/cli/..., and./pkg/..., is 5,042 covered blocks before and after, with none lost.smd statusandbss statusexit 6, and against a closed port they exit 7. Removing the classification fromsmd statusfails itsNetworkErrorrow. TheHTTPErrorrow doesn't fail on that change, becauseExitCodemaps the HTTP sentinel error toCodeHTTPby itself.Checklist
make test(or equivalent) locally and all tests passCONTRIBUTING.md)git commit -s) with my real name and email<filename>.licensesidecarLICENSES/directoryType of Change