Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

thaJeztah
Copy link
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 <[email protected]>
@codecov-commenter
Copy link

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
104 checks passed
@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