Skip to content

Commit 839dbbc

Browse files
committed
cli/command/images: set cmd.Args to prevent test-failures
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>
1 parent b64f265 commit 839dbbc

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

cli/command/image/load_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ func TestNewLoadCommandErrors(t *testing.T) {
2828
},
2929
{
3030
name: "input-to-terminal",
31+
args: []string{},
3132
isTerminalIn: true,
3233
expectedError: "requested load from stdin, but stdin is empty",
3334
},
3435
{
3536
name: "pull-error",
37+
args: []string{},
3638
expectedError: "something went wrong",
3739
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
3840
return image.LoadResponse{}, errors.Errorf("something went wrong")
@@ -71,12 +73,14 @@ func TestNewLoadCommandSuccess(t *testing.T) {
7173
}{
7274
{
7375
name: "simple",
76+
args: []string{},
7477
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
7578
return image.LoadResponse{Body: io.NopCloser(strings.NewReader("Success"))}, nil
7679
},
7780
},
7881
{
7982
name: "json",
83+
args: []string{},
8084
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
8185
json := "{\"ID\": \"1\"}"
8286
return image.LoadResponse{

0 commit comments

Comments
 (0)