test: fix ineffective mutex error-string assertion and add mirror cases - #2410
Merged
Conversation
The assertion checking the mutually exclusive error string used t.Logf instead of t.Errorf, so a wrong error message never failed the test. This masked that the message reports the flag's primary name (Names()[0]) rather than the alias typed on the command line. Align the expectation with the actual (and codebase-consistent) behavior. Also add coverage for cross-group combinations where the conflicting flag is not the first member of its group: --i --q and --s --q.
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.
What type of PR is this?
bugfix (test harness only)
What this PR does / why we need it:
Fixes #2404.
Found while reviewing #2386. Three changes in
flag_mutex_test.go:t.Logfinstead oft.Errorf/assert.Contains, so a wrong error message never failed thetest. This was masking that the message reports the flag's primary name
(
Names()[0]) rather than the alias typed on the command line.the primary flag name (consistent with how required-flag errors are
reported elsewhere in the codebase, e.g.
checkRequiredFlagincommand.go), so the--aiexpectation becomest.--i --q(first member of group 0 × second memberof group 1) and
--s --q(second member of group 0 × second member ofgroup 1) to pin the cross-group fix from Fix Issue #2385 #2386.
Which issue(s) this PR fixes
Fixes #2404
Testing
Ran
go test -count=1 -run TestFlagMutuallyExclusiveFlags -v .,go vet ./...,goimports -l ., andgo test -count=1 -race ./.... All pass.Release Notes