Skip to content

cli/command/images: set cmd.Args to prevent test-failures#5521

Merged
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:fix_test_args
Oct 8, 2024
Merged

cli/command/images: set cmd.Args to prevent test-failures#5521
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:fix_test_args

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

When running tests from my IDE, it compiles the tests before running, then executes the compiled binary to run the tests. Cobra doesn't like that, because in that situation os.Args is taken as argument for the command that's executed. The command that's tested now sees the test- flags as arguments (-test.v -test.run ..), which causes various tests to fail ("Command XYZ does not accept arguments").

# compile the tests:
go test -c -o foo.test

# execute the test:
./foo.test -test.v -test.run TestFoo
=== RUN   TestFoo
Error: "foo" accepts no arguments.

Set arguments to an empty slice to make sure it doesn't inherit arguments from the test-binary.

When running tests from my IDE, it compiles the tests before running,
then executes the compiled binary to run the tests. Cobra doesn't like that,
because in that situation os.Args is taken as argument for the command that's
executed. The command that's tested now sees the `test-` flags as arguments
(`-test.v -test.run ..`), which causes various tests to fail ("Command XYZ
does not accept arguments").

    # compile the tests:
    go test -c -o foo.test

    # execute the test:
    ./foo.test -test.v -test.run TestFoo
    === RUN   TestFoo
    Error: "foo" accepts no arguments.

Set arguments to an empty slice to make sure it doesn't inherit arguments
from the test-binary.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.57%. Comparing base (b64f265) to head (839dbbc).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5521      +/-   ##
==========================================
+ Coverage   60.19%   60.57%   +0.38%     
==========================================
  Files         342      345       +3     
  Lines       23448    23490      +42     
==========================================
+ Hits        14114    14229     +115     
+ Misses       8360     8289      -71     
+ Partials      974      972       -2     

@thaJeztah thaJeztah merged commit 2d47c9b into docker:master Oct 8, 2024
@thaJeztah thaJeztah deleted the fix_test_args branch October 8, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants