diff --git a/cli/command/checkpoint/list_test.go b/cli/command/checkpoint/list_test.go index 1c13f27755..26dd963a8c 100644 --- a/cli/command/checkpoint/list_test.go +++ b/cli/command/checkpoint/list_test.go @@ -1,14 +1,13 @@ package checkpoint import ( - "bytes" "io/ioutil" "testing" "github.com/docker/cli/cli/internal/test" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/testutil" - "github.com/docker/docker/pkg/testutil/golden" + "github.com/gotestyourself/gotestyourself/golden" "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -37,9 +36,9 @@ func TestCheckpointListErrors(t *testing.T) { } for _, tc := range testCases { - cli := test.NewFakeCliWithOutput(&fakeClient{ + cli := test.NewFakeCli(&fakeClient{ checkpointListFunc: tc.checkpointListFunc, - }, &bytes.Buffer{}) + }) cmd := newListCommand(cli) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) @@ -49,8 +48,7 @@ func TestCheckpointListErrors(t *testing.T) { func TestCheckpointListWithOptions(t *testing.T) { var containerID, checkpointDir string - buf := new(bytes.Buffer) - cli := test.NewFakeCliWithOutput(&fakeClient{ + cli := test.NewFakeCli(&fakeClient{ checkpointListFunc: func(container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) { containerID = container checkpointDir = options.CheckpointDir @@ -58,14 +56,12 @@ func TestCheckpointListWithOptions(t *testing.T) { {Name: "checkpoint-foo"}, }, nil }, - }, buf) + }) cmd := newListCommand(cli) cmd.SetArgs([]string{"container-foo"}) cmd.Flags().Set("checkpoint-dir", "/dir/foo") assert.NoError(t, cmd.Execute()) assert.Equal(t, "container-foo", containerID) assert.Equal(t, "/dir/foo", checkpointDir) - actual := buf.String() - expected := golden.Get(t, []byte(actual), "checkpoint-list-with-options.golden") - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), "checkpoint-list-with-options.golden") } diff --git a/cli/command/checkpoint/remove_test.go b/cli/command/checkpoint/remove_test.go index 3d85d16cda..976aa07892 100644 --- a/cli/command/checkpoint/remove_test.go +++ b/cli/command/checkpoint/remove_test.go @@ -1,7 +1,6 @@ package checkpoint import ( - "bytes" "io/ioutil" "testing" @@ -36,9 +35,9 @@ func TestCheckpointRemoveErrors(t *testing.T) { } for _, tc := range testCases { - cli := test.NewFakeCliWithOutput(&fakeClient{ + cli := test.NewFakeCli(&fakeClient{ checkpointDeleteFunc: tc.checkpointDeleteFunc, - }, &bytes.Buffer{}) + }) cmd := newRemoveCommand(cli) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) @@ -48,14 +47,14 @@ func TestCheckpointRemoveErrors(t *testing.T) { func TestCheckpointRemoveWithOptions(t *testing.T) { var containerID, checkpointID, checkpointDir string - cli := test.NewFakeCliWithOutput(&fakeClient{ + cli := test.NewFakeCli(&fakeClient{ checkpointDeleteFunc: func(container string, options types.CheckpointDeleteOptions) error { containerID = container checkpointID = options.CheckpointID checkpointDir = options.CheckpointDir return nil }, - }, &bytes.Buffer{}) + }) cmd := newRemoveCommand(cli) cmd.SetArgs([]string{"container-foo", "checkpoint-bar"}) cmd.Flags().Set("checkpoint-dir", "/dir/foo") diff --git a/cli/command/config/create_test.go b/cli/command/config/create_test.go index f2338d0038..7a6b2f54d3 100644 --- a/cli/command/config/create_test.go +++ b/cli/command/config/create_test.go @@ -11,7 +11,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/pkg/testutil" - "github.com/docker/docker/pkg/testutil/golden" + "github.com/gotestyourself/gotestyourself/golden" "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -71,8 +71,7 @@ func TestConfigCreateWithName(t *testing.T) { cmd := newConfigCreateCommand(cli) cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)}) assert.NoError(t, cmd.Execute()) - expected := golden.Get(t, actual, configDataFile) - assert.Equal(t, string(expected), string(actual)) + golden.Assert(t, string(actual), configDataFile) assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) } diff --git a/cli/command/config/inspect_test.go b/cli/command/config/inspect_test.go index e1af0b6b09..0431ffd652 100644 --- a/cli/command/config/inspect_test.go +++ b/cli/command/config/inspect_test.go @@ -1,7 +1,6 @@ package config import ( - "bytes" "fmt" "io/ioutil" "testing" @@ -13,7 +12,7 @@ import ( // Import builders to get the builder function as package function . "github.com/docker/cli/cli/internal/test/builders" "github.com/docker/docker/pkg/testutil" - "github.com/docker/docker/pkg/testutil/golden" + "github.com/gotestyourself/gotestyourself/golden" "github.com/stretchr/testify/assert" ) @@ -53,11 +52,10 @@ func TestConfigInspectErrors(t *testing.T) { }, } for _, tc := range testCases { - buf := new(bytes.Buffer) cmd := newConfigInspectCommand( - test.NewFakeCliWithOutput(&fakeClient{ + test.NewFakeCli(&fakeClient{ configInspectFunc: tc.configInspectFunc, - }, buf), + }), ) cmd.SetArgs(tc.args) for key, value := range tc.flags { @@ -95,17 +93,11 @@ func TestConfigInspectWithoutFormat(t *testing.T) { }, } for _, tc := range testCases { - buf := new(bytes.Buffer) - cmd := newConfigInspectCommand( - test.NewFakeCliWithOutput(&fakeClient{ - configInspectFunc: tc.configInspectFunc, - }, buf), - ) + cli := test.NewFakeCli(&fakeClient{configInspectFunc: tc.configInspectFunc}) + cmd := newConfigInspectCommand(cli) cmd.SetArgs(tc.args) assert.NoError(t, cmd.Execute()) - actual := buf.String() - expected := golden.Get(t, []byte(actual), fmt.Sprintf("config-inspect-without-format.%s.golden", tc.name)) - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-without-format.%s.golden", tc.name)) } } @@ -135,18 +127,14 @@ func TestConfigInspectWithFormat(t *testing.T) { }, } for _, tc := range testCases { - buf := new(bytes.Buffer) - cmd := newConfigInspectCommand( - test.NewFakeCliWithOutput(&fakeClient{ - configInspectFunc: tc.configInspectFunc, - }, buf), - ) + cli := test.NewFakeCli(&fakeClient{ + configInspectFunc: tc.configInspectFunc, + }) + cmd := newConfigInspectCommand(cli) cmd.SetArgs(tc.args) cmd.Flags().Set("format", tc.format) assert.NoError(t, cmd.Execute()) - actual := buf.String() - expected := golden.Get(t, []byte(actual), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name)) - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name)) } } @@ -172,16 +160,14 @@ func TestConfigInspectPretty(t *testing.T) { }, } for _, tc := range testCases { - buf := new(bytes.Buffer) - cmd := newConfigInspectCommand( - test.NewFakeCliWithOutput(&fakeClient{ - configInspectFunc: tc.configInspectFunc, - }, buf)) + cli := test.NewFakeCli(&fakeClient{ + configInspectFunc: tc.configInspectFunc, + }) + cmd := newConfigInspectCommand(cli) + cmd.SetArgs([]string{"configID"}) cmd.Flags().Set("pretty", "true") assert.NoError(t, cmd.Execute()) - actual := buf.String() - expected := golden.Get(t, []byte(actual), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name)) - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name)) } } diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index c8393caca5..f58e815a5b 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -13,7 +13,7 @@ import ( // Import builders to get the builder function as package function . "github.com/docker/cli/cli/internal/test/builders" "github.com/docker/docker/pkg/testutil" - "github.com/docker/docker/pkg/testutil/golden" + "github.com/gotestyourself/gotestyourself/golden" "github.com/stretchr/testify/assert" ) @@ -68,9 +68,7 @@ func TestConfigList(t *testing.T) { cmd := newConfigListCommand(cli) cmd.SetOutput(cli.OutBuffer()) assert.NoError(t, cmd.Execute()) - actual := cli.OutBuffer().String() - expected := golden.Get(t, []byte(actual), "config-list.golden") - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), "config-list.golden") } func TestConfigListWithQuietOption(t *testing.T) { @@ -87,9 +85,7 @@ func TestConfigListWithQuietOption(t *testing.T) { cmd := newConfigListCommand(cli) cmd.Flags().Set("quiet", "true") assert.NoError(t, cmd.Execute()) - actual := cli.OutBuffer().String() - expected := golden.Get(t, []byte(actual), "config-list-with-quiet-option.golden") - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden") } func TestConfigListWithConfigFormat(t *testing.T) { @@ -108,9 +104,7 @@ func TestConfigListWithConfigFormat(t *testing.T) { }) cmd := newConfigListCommand(cli) assert.NoError(t, cmd.Execute()) - actual := cli.OutBuffer().String() - expected := golden.Get(t, []byte(actual), "config-list-with-config-format.golden") - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), "config-list-with-config-format.golden") } func TestConfigListWithFormat(t *testing.T) { @@ -127,9 +121,7 @@ func TestConfigListWithFormat(t *testing.T) { cmd := newConfigListCommand(cli) cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") assert.NoError(t, cmd.Execute()) - actual := cli.OutBuffer().String() - expected := golden.Get(t, []byte(actual), "config-list-with-format.golden") - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), "config-list-with-format.golden") } func TestConfigListWithFilter(t *testing.T) { @@ -157,7 +149,5 @@ func TestConfigListWithFilter(t *testing.T) { cmd.Flags().Set("filter", "name=foo") cmd.Flags().Set("filter", "label=lbl1=Label-bar") assert.NoError(t, cmd.Execute()) - actual := cli.OutBuffer().String() - expected := golden.Get(t, []byte(actual), "config-list-with-filter.golden") - testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) + golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden") } diff --git a/cli/command/config/remove_test.go b/cli/command/config/remove_test.go index 2b2b28ae11..28cc41f670 100644 --- a/cli/command/config/remove_test.go +++ b/cli/command/config/remove_test.go @@ -1,7 +1,6 @@ package config import ( - "bytes" "io/ioutil" "strings" "testing" @@ -31,11 +30,10 @@ func TestConfigRemoveErrors(t *testing.T) { }, } for _, tc := range testCases { - buf := new(bytes.Buffer) cmd := newConfigRemoveCommand( - test.NewFakeCliWithOutput(&fakeClient{ + test.NewFakeCli(&fakeClient{ configRemoveFunc: tc.configRemoveFunc, - }, buf), + }), ) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) @@ -45,27 +43,25 @@ func TestConfigRemoveErrors(t *testing.T) { func TestConfigRemoveWithName(t *testing.T) { names := []string{"foo", "bar"} - buf := new(bytes.Buffer) var removedConfigs []string - cli := test.NewFakeCliWithOutput(&fakeClient{ + cli := test.NewFakeCli(&fakeClient{ configRemoveFunc: func(name string) error { removedConfigs = append(removedConfigs, name) return nil }, - }, buf) + }) cmd := newConfigRemoveCommand(cli) cmd.SetArgs(names) assert.NoError(t, cmd.Execute()) - assert.Equal(t, names, strings.Split(strings.TrimSpace(buf.String()), "\n")) + assert.Equal(t, names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")) assert.Equal(t, names, removedConfigs) } func TestConfigRemoveContinueAfterError(t *testing.T) { names := []string{"foo", "bar"} - buf := new(bytes.Buffer) var removedConfigs []string - cli := test.NewFakeCliWithOutput(&fakeClient{ + cli := test.NewFakeCli(&fakeClient{ configRemoveFunc: func(name string) error { removedConfigs = append(removedConfigs, name) if name == "foo" { @@ -73,7 +69,7 @@ func TestConfigRemoveContinueAfterError(t *testing.T) { } return nil }, - }, buf) + }) cmd := newConfigRemoveCommand(cli) cmd.SetArgs(names) diff --git a/cli/command/config/testdata/config-inspect-pretty.simple.golden b/cli/command/config/testdata/config-inspect-pretty.simple.golden index d5eefec543..60b5c7fa4a 100644 --- a/cli/command/config/testdata/config-inspect-pretty.simple.golden +++ b/cli/command/config/testdata/config-inspect-pretty.simple.golden @@ -1,8 +1,8 @@ -ID: configID -Name: configName +ID: configID +Name: configName Labels: - - lbl1=value1 -Created at: 0001-01-01 00:00:00+0000 utc -Updated at: 0001-01-01 00:00:00+0000 utc + - lbl1=value1 +Created at: 0001-01-01 00:00:00 +0000 utc +Updated at: 0001-01-01 00:00:00 +0000 utc Data: payload here diff --git a/cli/command/config/testdata/config-inspect-without-format.multiple-configs-with-labels.golden b/cli/command/config/testdata/config-inspect-without-format.multiple-configs-with-labels.golden index 6887c185f1..b01a400c57 100644 --- a/cli/command/config/testdata/config-inspect-without-format.multiple-configs-with-labels.golden +++ b/cli/command/config/testdata/config-inspect-without-format.multiple-configs-with-labels.golden @@ -1,7 +1,7 @@ [ { "ID": "ID-foo", - "Version": {}, + "Version": {}, "CreatedAt": "0001-01-01T00:00:00Z", "UpdatedAt": "0001-01-01T00:00:00Z", "Spec": { @@ -13,7 +13,7 @@ }, { "ID": "ID-bar", - "Version": {}, + "Version": {}, "CreatedAt": "0001-01-01T00:00:00Z", "UpdatedAt": "0001-01-01T00:00:00Z", "Spec": { diff --git a/cli/command/config/testdata/config-inspect-without-format.single-config.golden b/cli/command/config/testdata/config-inspect-without-format.single-config.golden index ea42ec6f4f..c4f41c1067 100644 --- a/cli/command/config/testdata/config-inspect-without-format.single-config.golden +++ b/cli/command/config/testdata/config-inspect-without-format.single-config.golden @@ -1,9 +1,9 @@ [ { "ID": "ID-foo", - "Version": {}, - "CreatedAt": "0001-01-01T00:00:00Z", - "UpdatedAt": "0001-01-01T00:00:00Z", + "Version": {}, + "CreatedAt": "0001-01-01T00:00:00Z", + "UpdatedAt": "0001-01-01T00:00:00Z", "Spec": { "Name": "foo", "Labels": null diff --git a/cli/command/config/testdata/config-list-with-config-format.golden b/cli/command/config/testdata/config-list-with-config-format.golden index 9a47538804..11c39229b8 100644 --- a/cli/command/config/testdata/config-list-with-config-format.golden +++ b/cli/command/config/testdata/config-list-with-config-format.golden @@ -1,2 +1,2 @@ -foo +foo bar label=label-bar diff --git a/cli/command/config/testdata/config-list-with-format.golden b/cli/command/config/testdata/config-list-with-format.golden index 9a47538804..11c39229b8 100644 --- a/cli/command/config/testdata/config-list-with-format.golden +++ b/cli/command/config/testdata/config-list-with-format.golden @@ -1,2 +1,2 @@ -foo +foo bar label=label-bar