diff --git a/cli/command/context/list_test.go b/cli/command/context/list_test.go index 98ac2e480c..1b264a6e85 100644 --- a/cli/command/context/list_test.go +++ b/cli/command/context/list_test.go @@ -8,6 +8,13 @@ import ( "gotest.tools/v3/golden" ) +func createTestContexts(t *testing.T, cli command.Cli, name ...string) { + t.Helper() + for _, n := range name { + createTestContext(t, cli, n) + } +} + func createTestContext(t *testing.T, cli command.Cli, name string) { t.Helper() @@ -21,9 +28,7 @@ func createTestContext(t *testing.T, cli command.Cli, name string) { func TestList(t *testing.T) { cli := makeFakeCli(t) - createTestContext(t, cli, "current") - createTestContext(t, cli, "other") - createTestContext(t, cli, "unset") + createTestContexts(t, cli, "current", "other", "unset") cli.SetCurrentContext("current") cli.OutBuffer().Reset() assert.NilError(t, runList(cli, &listOptions{})) @@ -32,8 +37,7 @@ func TestList(t *testing.T) { func TestListQuiet(t *testing.T) { cli := makeFakeCli(t) - createTestContext(t, cli, "current") - createTestContext(t, cli, "other") + createTestContexts(t, cli, "current", "other") cli.SetCurrentContext("current") cli.OutBuffer().Reset() assert.NilError(t, runList(cli, &listOptions{quiet: true})) diff --git a/cli/command/context/remove_test.go b/cli/command/context/remove_test.go index 35e27781b2..f42c4fe7eb 100644 --- a/cli/command/context/remove_test.go +++ b/cli/command/context/remove_test.go @@ -13,8 +13,7 @@ import ( func TestRemove(t *testing.T) { cli := makeFakeCli(t) - createTestContext(t, cli, "current") - createTestContext(t, cli, "other") + createTestContexts(t, cli, "current", "other") assert.NilError(t, RunRemove(cli, RemoveOptions{}, []string{"other"})) _, err := cli.ContextStore().GetMetadata("current") assert.NilError(t, err) @@ -24,8 +23,7 @@ func TestRemove(t *testing.T) { func TestRemoveNotAContext(t *testing.T) { cli := makeFakeCli(t) - createTestContext(t, cli, "current") - createTestContext(t, cli, "other") + createTestContexts(t, cli, "current", "other") err := RunRemove(cli, RemoveOptions{}, []string{"not-a-context"}) assert.ErrorContains(t, err, `context "not-a-context" does not exist`) @@ -35,8 +33,7 @@ func TestRemoveNotAContext(t *testing.T) { func TestRemoveCurrent(t *testing.T) { cli := makeFakeCli(t) - createTestContext(t, cli, "current") - createTestContext(t, cli, "other") + createTestContexts(t, cli, "current", "other") cli.SetCurrentContext("current") err := RunRemove(cli, RemoveOptions{}, []string{"current"}) assert.ErrorContains(t, err, `context "current" is in use, set -f flag to force remove`) @@ -50,8 +47,7 @@ func TestRemoveCurrentForce(t *testing.T) { assert.NilError(t, testCfg.Save()) cli := makeFakeCli(t, withCliConfig(testCfg)) - createTestContext(t, cli, "current") - createTestContext(t, cli, "other") + createTestContexts(t, cli, "current", "other") cli.SetCurrentContext("current") assert.NilError(t, RunRemove(cli, RemoveOptions{Force: true}, []string{"current"})) reloadedConfig, err := config.Load(configDir) diff --git a/cli/command/context/update_test.go b/cli/command/context/update_test.go index 5bad6dec2f..553f67fd1a 100644 --- a/cli/command/context/update_test.go +++ b/cli/command/context/update_test.go @@ -6,7 +6,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/context/docker" "gotest.tools/v3/assert" - "gotest.tools/v3/assert/cmp" + is "gotest.tools/v3/assert/cmp" ) func TestUpdateDescriptionOnly(t *testing.T) { @@ -46,7 +46,7 @@ func TestUpdateDockerOnly(t *testing.T) { dc, err := command.GetDockerContext(c) assert.NilError(t, err) assert.Equal(t, dc.Description, "description of test") - assert.Check(t, cmp.Contains(c.Endpoints, docker.DockerEndpoint)) + assert.Check(t, is.Contains(c.Endpoints, docker.DockerEndpoint)) assert.Equal(t, c.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta).Host, "tcp://some-host") }