2018-11-09 09:10:41 -05:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/cli/cli/command"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/env"
|
|
|
|
"gotest.tools/v3/golden"
|
2018-11-09 09:10:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func createTestContextWithKubeAndSwarm(t *testing.T, cli command.Cli, name string, orchestrator string) {
|
|
|
|
revert := env.Patch(t, "KUBECONFIG", "./testdata/test-kubeconfig")
|
|
|
|
defer revert()
|
|
|
|
|
2019-01-21 03:37:20 -05:00
|
|
|
err := RunCreate(cli, &CreateOptions{
|
|
|
|
Name: name,
|
|
|
|
DefaultStackOrchestrator: orchestrator,
|
|
|
|
Description: "description of " + name,
|
2019-03-22 10:20:40 -04:00
|
|
|
Kubernetes: map[string]string{keyFrom: "default"},
|
2021-04-30 03:31:41 -04:00
|
|
|
Docker: map[string]string{keyHost: "https://someswarmserver.example.com"},
|
2018-11-09 09:10:41 -05:00
|
|
|
})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestList(t *testing.T) {
|
2022-02-25 07:07:16 -05:00
|
|
|
cli := makeFakeCli(t)
|
2018-11-09 09:10:41 -05:00
|
|
|
createTestContextWithKubeAndSwarm(t, cli, "current", "all")
|
|
|
|
createTestContextWithKubeAndSwarm(t, cli, "other", "all")
|
|
|
|
createTestContextWithKubeAndSwarm(t, cli, "unset", "unset")
|
|
|
|
cli.SetCurrentContext("current")
|
|
|
|
cli.OutBuffer().Reset()
|
|
|
|
assert.NilError(t, runList(cli, &listOptions{}))
|
|
|
|
golden.Assert(t, cli.OutBuffer().String(), "list.golden")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListQuiet(t *testing.T) {
|
2022-02-25 07:07:16 -05:00
|
|
|
cli := makeFakeCli(t)
|
2018-11-09 09:10:41 -05:00
|
|
|
createTestContextWithKubeAndSwarm(t, cli, "current", "all")
|
|
|
|
createTestContextWithKubeAndSwarm(t, cli, "other", "all")
|
|
|
|
cli.SetCurrentContext("current")
|
|
|
|
cli.OutBuffer().Reset()
|
|
|
|
assert.NilError(t, runList(cli, &listOptions{quiet: true}))
|
|
|
|
golden.Assert(t, cli.OutBuffer().String(), "quiet-list.golden")
|
|
|
|
}
|