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 {
cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{ t.Run(tc.name, func(t *testing.T) {
imageRemoveFunc: tc.imageRemoveFunc, cmd := NewRemoveCommand(test.NewFakeCli(&fakeClient{
})) imageRemoveFunc: tc.imageRemoveFunc,
cmd.SetOutput(ioutil.Discard) }))
cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) cmd.SetArgs(tc.args)
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 {
cli := test.NewFakeCli(&fakeClient{imageRemoveFunc: tc.imageRemoveFunc}) t.Run(tc.name, func(t *testing.T) {
cmd := NewRemoveCommand(cli) cli := test.NewFakeCli(&fakeClient{imageRemoveFunc: tc.imageRemoveFunc})
cmd.SetOutput(ioutil.Discard) cmd := NewRemoveCommand(cli)
cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard)
assert.NoError(t, cmd.Execute()) cmd.SetArgs(tc.args)
if tc.expectedErrMsg != "" { assert.NoError(t, cmd.Execute())
assert.Equal(t, tc.expectedErrMsg, cli.ErrBuffer().String()) assert.Equal(t, tc.expectedStderr, 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)) })
} }
} }