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/golden"
|
2018-11-09 09:10:41 -05:00
|
|
|
)
|
|
|
|
|
2022-02-24 06:59:15 -05:00
|
|
|
func createTestContext(t *testing.T, cli command.Cli, name string) {
|
|
|
|
t.Helper()
|
2018-11-09 09:10:41 -05:00
|
|
|
|
2019-01-21 03:37:20 -05:00
|
|
|
err := RunCreate(cli, &CreateOptions{
|
2022-02-24 06:59:15 -05:00
|
|
|
Name: name,
|
|
|
|
Description: "description of " + name,
|
|
|
|
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) {
|
|
|
|
cli, cleanup := makeFakeCli(t)
|
|
|
|
defer cleanup()
|
2022-02-24 06:59:15 -05:00
|
|
|
createTestContext(t, cli, "current")
|
|
|
|
createTestContext(t, cli, "other")
|
|
|
|
createTestContext(t, cli, "unset")
|
2018-11-09 09:10:41 -05:00
|
|
|
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) {
|
|
|
|
cli, cleanup := makeFakeCli(t)
|
|
|
|
defer cleanup()
|
2022-02-24 06:59:15 -05:00
|
|
|
createTestContext(t, cli, "current")
|
|
|
|
createTestContext(t, cli, "other")
|
2018-11-09 09:10:41 -05:00
|
|
|
cli.SetCurrentContext("current")
|
|
|
|
cli.OutBuffer().Reset()
|
|
|
|
assert.NilError(t, runList(cli, &listOptions{quiet: true}))
|
|
|
|
golden.Assert(t, cli.OutBuffer().String(), "quiet-list.golden")
|
|
|
|
}
|