Use t.Run() for tests

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-10-30 12:57:40 -04:00
parent 125302cfa6
commit b900676523
2 changed files with 19 additions and 18 deletions

View File

@ -64,12 +64,14 @@ func TestNewRemoveCommandErrors(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{ cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{
imageRemoveFunc: tc.imageRemoveFunc, imageRemoveFunc: tc.imageRemoveFunc,
})) }))
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
})
} }
} }
@ -78,7 +80,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
name string name string
args []string args []string
imageRemoveFunc func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) imageRemoveFunc func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
expectedErrMsg string expectedStderr string
}{ }{
{ {
name: "Image Deleted", name: "Image Deleted",
@ -96,7 +98,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
assert.Equal(t, true, options.Force) assert.Equal(t, true, options.Force)
return []types.ImageDeleteResponseItem{}, notFound{"image1"} return []types.ImageDeleteResponseItem{}, notFound{"image1"}
}, },
expectedErrMsg: "Error: No such image: image1", expectedStderr: "Error: No such image: image1",
}, },
{ {
@ -119,14 +121,14 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{imageRemoveFunc: tc.imageRemoveFunc}) cli := test.NewFakeCli(&fakeClient{imageRemoveFunc: tc.imageRemoveFunc})
cmd := NewRemoveCommand(cli) cmd := NewRemoveCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
if tc.expectedErrMsg != "" { assert.Equal(t, tc.expectedStderr, cli.ErrBuffer().String())
assert.Equal(t, tc.expectedErrMsg, cli.ErrBuffer().String())
}
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("remove-command-success.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("remove-command-success.%s.golden", tc.name))
})
} }
} }