Repository navigation
Conversation
synackd
marked this pull request as ready for review
October 23, 2026 04:32
synackd
force-pushed
the
test/organize
branch
2 times, most recently
from
October 23, 2026 16:26
94190fa to
2c98ca0
Compare
synackd
added a commit
that referenced
this pull request
Oct 23, 2026
Replace the two SMD-specific CA cases with a shared matrix of all 108 network commands to verify trust consistently across the command tree. Keep the cross-family behavior tests in cacert_test.go to follow the file organization documented in PR #218. Check that each command rejects the TLS server without a trusted CA and succeeds with --cacert. Reuse the same invocations for missing-CA tests and compare the matrix with network leaf commands exposing --uri so new commands cannot silently miss CA coverage. Reuse existing payload fixtures and keep server setup in one place to limit duplication. Fix the RCS console trust failure exposed by the broader tests. Clone the WebSocket dialer and use the HTTP client's TLS configuration at dial time to honor CA certificates loaded after client construction. Keep trust settings local to each connection instead of changing the shared dialer. Remove an unused errcheck suppression flagged by lint in the same file. Preserve behavior through TLS requests rather than asserting certificate load counts, which would couple tests to the refactor's implementation. Validate with go test -race ./... -count=1 and golangci-lint run. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
11 of 17 tasks
synackd
added a commit
that referenced
this pull request
Oct 23, 2026
Replace the two SMD-specific CA cases from #216 with a shared matrix of all 108 network commands to verify trust consistently across the tree. Keep cross-family behavior tests in cacert_test.go to follow the file organization documented in #218 without including its reorganization. Check that each command rejects an untrusted TLS server and succeeds with --cacert. Reuse the same invocations for missing-CA tests and compare the matrix with network leaf commands exposing --uri so new commands cannot silently miss CA coverage. Reuse existing payload fixtures and keep server setup in one place to limit duplication. Fix RCS console trust by cloning the WebSocket dialer and the HTTP client's TLS configuration at dial time. Honor certificates loaded after client construction and keep trust settings local to each connection. Explicitly discard post-interrupt read errors to preserve a clean exit and satisfy both supported local and CI linter versions. Keep the test server open until the console client sends its WebSocket close reply and TLS close notification to avoid broken pipes on Linux. Bound the drain with a read deadline and await the hijacked handler before ending the test, since httptest.Server.Close does not wait for it. Verify behavior through TLS requests rather than counting certificate loads, which would couple tests to the refactor's implementation. Validate with make test PARALLEL=4, make coverage PARALLEL=4, 100 race runs of both console TLS cases, and golangci-lint v2.15.0. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
Tests of the smd resource commands were spread across smd_test.go, smd_errors_test.go, smd_write_test.go, and smd_write_errors_test.go as well as each resource's own files, so the tests for one command had no single home. Move each smd group, group member, iface, rfe, and compep test into its resource's smd_<resource>_test.go or _errors_test.go file, leaving smd_test.go and smd_errors_test.go with only the commands directly under smd and the TestSMDDelete_* tables over every smd resource. Retire smd_write_test.go and smd_write_errors_test.go. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
bss_test.go and bss_errors_test.go held tests for every bss command, and the boot params set/update tests sat in bss_params_write_test.go and bss_params_write_errors_test.go, so the tests for one command were split across files. Move the boot params, boot script, boot image, and hosts tests into bss_boot_params_test.go, bss_boot_script_test.go, bss_boot_image_test.go, and bss_hosts_test.go and their _errors_test.go companions, leaving bss_test.go and bss_errors_test.go with only the commands directly under bss. Retire the bss_params_write files. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
The add, set, patch, and delete tests of the boot and metadata commands sat in boot_write_test.go and metadata_write_test.go (and their _errors_test.go companions), apart from the other tests of the same subjects in boot_test.go and metadata_test.go. Fold the write files into the family files, which hold the tables over every resource type, and move the tests of a single resource type's commands into boot_<type>_errors_test.go and metadata_group_test.go. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
cloud_init_test.go held happy-path tests for the group, node, and defaults commands, whose other tests live in cloud_init_group_test.go and cloud_init_node_test.go. Move them into the matching cloud_init_<command>_test.go files, and the defaults tests into new cloud_init_defaults_test.go and cloud_init_defaults_errors_test.go files, leaving cloud_init_test.go with only the service commands. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
pcs_test.go and pcs_errors_test.go held the pcs status tests next to the service ones, and pcs_flags_test.go and pcs_flags_errors_test.go held one flag test each for subjects whose other tests live elsewhere. Move the status tests into new pcs_status_test.go and pcs_status_errors_test.go files, and the flag tests into the files of the commands they cover, retiring the pcs_flags files. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
rcs_test.go and rcs_errors_test.go hold only tests of the "rcs console" commands. Rename them rcs_console_test.go and rcs_console_errors_test.go so the file names follow the command path, as for the other families. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
"discover static" is the only command under "discover", so its tests belong in the family files, as the tests of "bss dumpstate" and "bss history" are in bss_test.go. Rename discover_static_test.go and discover_static_errors_test.go to discover_test.go and discover_errors_test.go, and move the one TestDiscoverStatic test in discover_static_flags_test.go into discover_test.go, retiring the topic file. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
Seven tests in config*_test.go run "version" or "smd group get", not the "config" commands: they check that the root command loads the config file and resolves a command's base URI and token from its cluster. Move them to root_test.go, root_errors_test.go, and a new root_boundary_test.go, keeping each test's bucket. Rename the two boundary tests from TestConfig_* to TestRootCommand_* so the TestConfig boundary tests stay in one file. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
The CheckToken, HandleToken, and IOStreams tests were each spread over two or three files, and TestRuntime_EnvironmentIsolation was named for the whole Runtime though it tests SetTokenFromEnv. Move the lone CheckToken and HandleToken tests into cli_test.go with the others for their method, retiring cli_token_validation_test.go, and the IOStreams tests (with the reader and writer stubs only they use) into runtime_test.go beside the IOStreams accessors test. Rename TestRuntime_EnvironmentIsolation to TestSetTokenFromEnv_PerRuntimeEnvironment and move it next to the other SetTokenFromEnv test. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
The happy-path ReadConfigWithDefaults tests were split across clusterdefaults_test.go, configfile_test.go, and validate_test.go. Move them, with their temp-file helpers, into configfile_test.go next to the function's other tests, and rename clusterdefaults_errors_test.go to configfile_errors_test.go to match. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
TestUseCACert_FileFailures sat in request_layer_errors_test.go and TestShowConsole_ReturnsConnectionCloseError in session_errors_test.go, apart from the other error tests of the same functions. Move them into client_errors_test.go and rcs_errors_test.go. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
The tests in transaction_test.go and transaction_errors_test.go shared the TestFile_ subject with the per-method tests in file_test.go and file_errors_test.go, though they cover the staged write that File.Update performs for every mutation. Rename them TestFileUpdate_* so each file holds a distinct subject. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
loadmerged_test.go held one LoadMerged test and one UserConfigPath test apart from the others for those functions in config_test.go. Move them there and retire loadmerged_test.go. No test logic changes. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
CONTRIBUTING.md's suffix taxonomy implies one file per subject and bucket, but nothing enforced it, so tests of one subject spread across several files as new batches added new files. Add a source check that flags a subject (the part of a test's name before its first underscore) whose tests in one bucket (plain, _errors, or _boundary) are in more than one file of a package. Files that build only on some platforms, by a //go:build constraint or a GOOS/GOARCH file name suffix, are exempt. Add fixtures for a split subject and an exempt platform file. Document the rule in CONTRIBUTING.md, along with naming command tests after the command path they cover. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
synackd
force-pushed
the
test/organize
branch
from
October 23, 2026 22:38
2c98ca0 to
1134d33
Compare
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 #190
Summary
CONTRIBUTING.mdgroups a subject's tests by suffix (<subject>_test.go,_errors_test.go,_boundary_test.go), but 48 subject/bucket pairs onmainwere split across two or three files. This PR moves each test intoone file per subject and bucket and adds a check so the layout can't drift
back.
This change only moves tests. Apart from 9 renames, every moved test,
helper and fixture is byte-identical to
mainand stays in its package.The test count goes from 967 to 968; the one new test is the check.
In
cmd, each test file is named after the command path it covers, with onecommit per family:
smdsmd_test.goandsmd_write*_test.gointosmd_{group,group_member,iface,rfe,compep}*_test.go.smd_test.gokeeps onlyTestSMDServiceStatus.bssbss_boot_params,bss_boot_scriptandbss_hoststest files.TestBSSBootImageSetmoves tobss_boot_image_test.go.bss_test.gokeeps the commands directly underbss(dumpstate,history,service status, deprecatedstatus).boot,metadata*_write*_test.gois folded into the family files. Newboot_{bmc,config,node}_errors_test.goandmetadata_group_test.go.cloud-initcloud_init_defaults*_test.go.cloud_init_test.gokeeps only the service tests.pcspcs_status*_test.go.pcs_flags*_test.gois retired, andTestPCSTransitionStart_RequiresXnamemoves topcs_transition_errors_test.go.rcsrcs*_test.go→rcs_console*_test.go(every test coversrcs console).discoverdiscover staticis the only command underdiscover, sodiscover_static*_test.go→discover*_test.go, anddiscover_static_flags_test.gois folded in.config*_test.gothat runversionorsmd group get, notconfig, move toroot*_test.go(newroot_boundary_test.go). They check how the root command loads config and resolves a command's base URI and token.The
_writefiles' fixtures (bootAddPayload,metadataTypes,addPayloadFor) moved with their users. Each moved file's file-level commentnow describes what the file holds.
Outside
cmd, tests of the same function that lived in different fileswere moved together:
internal/cli: theCheckToken/HandleTokentests go tocli_test.go(removing
cli_token_validation_test.go). TheIOStreamstests and theirreadError/writeErrorstubs go toruntime_test.go.internal/configfile: theReadConfigWithDefaultstests and theirwriteTemp/writeCfghelpers go toconfigfile_test.go(removingclusterdefaults_test.goandvalidate_test.go).clusterdefaults_errors_test.go→configfile_errors_test.go.pkg/client:TestUseCACert_FileFailuresgoes toclient_errors_test.go.TestShowConsole_ReturnsConnectionCloseErrorgoes torcs/rcs_errors_test.go.pkg/config: theloadmerged_test.gotests go toconfig_test.go.These tests are renamed:
TestRuntime_EnvironmentIsolation→TestSetTokenFromEnv_PerRuntimeEnvironment.TestFile_*tests inpkg/config/transaction*_test.go→TestFileUpdate_*, since everyFilemutation goes throughFile.Update.TestConfig_NullValueHandlingandTestConfig_IgnoreConfigSkipsConfigFile→
TestRootCommand_*, since they moved toroot_boundary_test.goand theother
TestConfigboundary tests stay inconfig_boundary_test.go.Tests
The last commit adds
TestTestFiles_SubjectInOneFiletointernal/conventions. It flags any subject (the part of a test name beforethe first
_) that has tests of one bucket in more than one file. Fileslimited to some platforms, by a
//go:buildline or a GOOS/GOARCH file-namesuffix, are exempt. New fixtures in
testdata/violations(widget_test.goand
widget_windows_test.go) check that it flags a split and allows theplatform exception.
CONTRIBUTING.mdnow documents the one-file rule, the platform exception andthe command-path naming in
cmd.Review notes
git diff --color-moved(or--color-moved=dimmed-zebra) shows that the moved code isunchanged.
TestSMDDelete_*tables go tosmd_errors_test.go, notcommands_errors_test.goor per-resource tests as the issue suggested. Theyonly cover
smd, and other single-family tables (TestBootAdd_*,TestMetadataAdd_*,TestCloudInit_MalformedSuccessResponses) already sitin their family files. The issue's two options would either put a
single-family table in the cross-family file or change test logic.
CONTRIBUTING.mddocuments the resulting rule: tables over every resourceof one family stay in the family file, error tables across families go to
commands_errors_test.go, and other cross-family tests go in a file namedafter the behavior they check (
prompts_test.go,service_status_test.go).cmd. Only twowere too broad to group (
TestRuntime,TestFile). The other splitsubjects named one specific function (
CheckToken,HandleToken,ReadConfigWithDefaults,UseCACert,ShowConsole,LoadMerged), so theywere moved together instead of renamed.
commands_errors_test.goare left as is. The issue marks that question asout of scope.
Manual testing
The split-subject script from #190 now reports only the platform-specific
files (
sync_windows_test.go;owner*_test.gois//go:build unix) and thecheck's own fixtures:
Checklist
make test(or equivalent) locally and all tests pass(
CONTRIBUTING.md)git commit -s) with my real name and email<filename>.licensesidecarLICENSES/directoryType of Change