Skip to content

test(cmd): reset cobra flags between runs so -count is usable - #124

Merged
sylvesterdamgaard merged 2 commits into
mainfrom
fix/cmd-test-flag-isolation
Aug 27, 2026
Merged

test(cmd): reset cobra flags between runs so -count is usable#124
sylvesterdamgaard merged 2 commits into
mainfrom
fix/cmd-test-flag-isolation

Conversation

@sylvesterdamgaard

Copy link
Copy Markdown
Contributor

These tests drive the shared global rootCmd, and cobra flag values are sticky:
once "version --short" has run, --short stays set on that command, so a later
plain "version" printed only the number. Within one run the subtests happened to
be ordered such that this never showed; under -count=2 four tests fail.

That made -count unusable for this package — and a test that only passes in one
particular order is a test that can hide a real regression just as easily. Flags
are now reset to their defaults before each execution. Pre-existing: v2.5.1
fails the same way.

These tests drive the shared global rootCmd, and cobra flag values are sticky:
once "version --short" has run, --short stays set on that command, so a later
plain "version" printed only the number. Within one run the subtests happened to
be ordered such that this never showed; under -count=2 four tests fail.

That made -count unusable for this package — and a test that only passes in one
particular order is a test that can hide a real regression just as easily. Flags
are now reset to their defaults before each execution. Pre-existing: v2.5.1
fails the same way.
The flag-reset helper imports pflag directly (cobra's FlagSet.VisitAll takes a
*pflag.Flag), so go.mod and the SBOM record it as direct rather than indirect.
No new module enters the graph — cobra already pulled it in.
@sylvesterdamgaard
sylvesterdamgaard merged commit 17119dc into main Aug 27, 2026
9 checks passed
@sylvesterdamgaard
sylvesterdamgaard deleted the fix/cmd-test-flag-isolation branch August 27, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant