github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/context/list_test.go (about) 1 package context 2 3 import ( 4 "testing" 5 6 "github.com/docker/cli/cli/command" 7 "gotest.tools/v3/assert" 8 "gotest.tools/v3/env" 9 "gotest.tools/v3/golden" 10 ) 11 12 func createTestContextWithKubeAndSwarm(t *testing.T, cli command.Cli, name string, orchestrator string) { 13 revert := env.Patch(t, "KUBECONFIG", "./testdata/test-kubeconfig") 14 defer revert() 15 16 err := RunCreate(cli, &CreateOptions{ 17 Name: name, 18 DefaultStackOrchestrator: orchestrator, 19 Description: "description of " + name, 20 Kubernetes: map[string]string{keyFrom: "default"}, 21 Docker: map[string]string{keyHost: "https://someswarmserver"}, 22 }) 23 assert.NilError(t, err) 24 } 25 26 func TestList(t *testing.T) { 27 cli, cleanup := makeFakeCli(t) 28 defer cleanup() 29 createTestContextWithKubeAndSwarm(t, cli, "current", "all") 30 createTestContextWithKubeAndSwarm(t, cli, "other", "all") 31 createTestContextWithKubeAndSwarm(t, cli, "unset", "unset") 32 cli.SetCurrentContext("current") 33 cli.OutBuffer().Reset() 34 assert.NilError(t, runList(cli, &listOptions{})) 35 golden.Assert(t, cli.OutBuffer().String(), "list.golden") 36 } 37 38 func TestListQuiet(t *testing.T) { 39 cli, cleanup := makeFakeCli(t) 40 defer cleanup() 41 createTestContextWithKubeAndSwarm(t, cli, "current", "all") 42 createTestContextWithKubeAndSwarm(t, cli, "other", "all") 43 cli.SetCurrentContext("current") 44 cli.OutBuffer().Reset() 45 assert.NilError(t, runList(cli, &listOptions{quiet: true})) 46 golden.Assert(t, cli.OutBuffer().String(), "quiet-list.golden") 47 }