mirror of https://github.com/docker/cli.git
cli/command/context: list: add test for JSON output
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 40a1da8b42
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e23a63eb4c
commit
29cd8591ee
|
@ -4,6 +4,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/golden"
|
||||
)
|
||||
|
@ -37,6 +38,33 @@ func TestList(t *testing.T) {
|
|||
golden.Assert(t, cli.OutBuffer().String(), "list.golden")
|
||||
}
|
||||
|
||||
func TestListJSON(t *testing.T) {
|
||||
cli := makeFakeCli(t)
|
||||
createTestContext(t, cli, "current", nil)
|
||||
createTestContext(t, cli, "context1", map[string]any{"Type": "aci"})
|
||||
createTestContext(t, cli, "context2", map[string]any{"Type": "ecs"})
|
||||
createTestContext(t, cli, "context3", map[string]any{"Type": "moby"})
|
||||
cli.SetCurrentContext("current")
|
||||
|
||||
t.Run("format={{json .}}", func(t *testing.T) {
|
||||
cli.OutBuffer().Reset()
|
||||
assert.NilError(t, runList(cli, &listOptions{format: formatter.JSONFormat}))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "list-json.golden")
|
||||
})
|
||||
|
||||
t.Run("format=json", func(t *testing.T) {
|
||||
cli.OutBuffer().Reset()
|
||||
assert.NilError(t, runList(cli, &listOptions{format: formatter.JSONFormatKey}))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "list-json.golden")
|
||||
})
|
||||
|
||||
t.Run("format={{ json .Name }}", func(t *testing.T) {
|
||||
cli.OutBuffer().Reset()
|
||||
assert.NilError(t, runList(cli, &listOptions{format: `{{ json .Name }}`}))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "list-json-name.golden")
|
||||
})
|
||||
}
|
||||
|
||||
func TestListQuiet(t *testing.T) {
|
||||
cli := makeFakeCli(t)
|
||||
createTestContexts(t, cli, "current", "other")
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
"context1"
|
||||
"context2"
|
||||
"context3"
|
||||
"current"
|
||||
"default"
|
|
@ -0,0 +1,5 @@
|
|||
{"Current":false,"Description":"description of context1","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"context1"}
|
||||
{"Current":false,"Description":"description of context2","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"context2"}
|
||||
{"Current":false,"Description":"description of context3","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"context3"}
|
||||
{"Current":true,"Description":"description of current","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"current"}
|
||||
{"Current":false,"Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"unix:///var/run/docker.sock","Error":"","Name":"default"}
|
Loading…
Reference in New Issue