Update stack and task command tests to new golden
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 1dd742eac8
Component: cli
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -13,8 +12,7 @@ import (
|
||||
. "github.com/docker/cli/cli/internal/test/builders"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/pkg/testutil"
|
||||
"github.com/docker/docker/pkg/testutil/golden"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -22,75 +20,60 @@ func TestTaskPrintWithQuietOption(t *testing.T) {
|
||||
quiet := true
|
||||
trunc := false
|
||||
noResolve := true
|
||||
buf := new(bytes.Buffer)
|
||||
apiClient := &fakeClient{}
|
||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
||||
tasks := []swarm.Task{
|
||||
*Task(TaskID("id-foo")),
|
||||
}
|
||||
cli := test.NewFakeCli(apiClient)
|
||||
tasks := []swarm.Task{*Task(TaskID("id-foo"))}
|
||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey)
|
||||
assert.NoError(t, err)
|
||||
actual := buf.String()
|
||||
expected := golden.Get(t, []byte(actual), "task-print-with-quiet-option.golden")
|
||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-quiet-option.golden")
|
||||
}
|
||||
|
||||
func TestTaskPrintWithNoTruncOption(t *testing.T) {
|
||||
quiet := false
|
||||
trunc := false
|
||||
noResolve := true
|
||||
buf := new(bytes.Buffer)
|
||||
apiClient := &fakeClient{}
|
||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
||||
cli := test.NewFakeCli(apiClient)
|
||||
tasks := []swarm.Task{
|
||||
*Task(TaskID("id-foo-yov6omdek8fg3k5stosyp2m50")),
|
||||
}
|
||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .ID }}")
|
||||
assert.NoError(t, err)
|
||||
actual := buf.String()
|
||||
expected := golden.Get(t, []byte(actual), "task-print-with-no-trunc-option.golden")
|
||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-no-trunc-option.golden")
|
||||
}
|
||||
|
||||
func TestTaskPrintWithGlobalService(t *testing.T) {
|
||||
quiet := false
|
||||
trunc := false
|
||||
noResolve := true
|
||||
buf := new(bytes.Buffer)
|
||||
apiClient := &fakeClient{}
|
||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
||||
cli := test.NewFakeCli(apiClient)
|
||||
tasks := []swarm.Task{
|
||||
*Task(TaskServiceID("service-id-foo"), TaskNodeID("node-id-bar"), TaskSlot(0)),
|
||||
}
|
||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}")
|
||||
assert.NoError(t, err)
|
||||
actual := buf.String()
|
||||
expected := golden.Get(t, []byte(actual), "task-print-with-global-service.golden")
|
||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-global-service.golden")
|
||||
}
|
||||
|
||||
func TestTaskPrintWithReplicatedService(t *testing.T) {
|
||||
quiet := false
|
||||
trunc := false
|
||||
noResolve := true
|
||||
buf := new(bytes.Buffer)
|
||||
apiClient := &fakeClient{}
|
||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
||||
cli := test.NewFakeCli(apiClient)
|
||||
tasks := []swarm.Task{
|
||||
*Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
|
||||
}
|
||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}")
|
||||
assert.NoError(t, err)
|
||||
actual := buf.String()
|
||||
expected := golden.Get(t, []byte(actual), "task-print-with-replicated-service.golden")
|
||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-replicated-service.golden")
|
||||
}
|
||||
|
||||
func TestTaskPrintWithIndentation(t *testing.T) {
|
||||
quiet := false
|
||||
trunc := false
|
||||
noResolve := false
|
||||
buf := new(bytes.Buffer)
|
||||
apiClient := &fakeClient{
|
||||
serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
||||
return *Service(ServiceName("service-name-foo")), nil, nil
|
||||
@@ -99,7 +82,7 @@ func TestTaskPrintWithIndentation(t *testing.T) {
|
||||
return *Node(NodeName("node-name-bar")), nil, nil
|
||||
},
|
||||
}
|
||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
||||
cli := test.NewFakeCli(apiClient)
|
||||
tasks := []swarm.Task{
|
||||
*Task(
|
||||
TaskID("id-foo"),
|
||||
@@ -120,16 +103,13 @@ func TestTaskPrintWithIndentation(t *testing.T) {
|
||||
}
|
||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey)
|
||||
assert.NoError(t, err)
|
||||
actual := buf.String()
|
||||
expected := golden.Get(t, []byte(actual), "task-print-with-indentation.golden")
|
||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-indentation.golden")
|
||||
}
|
||||
|
||||
func TestTaskPrintWithResolution(t *testing.T) {
|
||||
quiet := false
|
||||
trunc := false
|
||||
noResolve := false
|
||||
buf := new(bytes.Buffer)
|
||||
apiClient := &fakeClient{
|
||||
serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
||||
return *Service(ServiceName("service-name-foo")), nil, nil
|
||||
@@ -138,13 +118,11 @@ func TestTaskPrintWithResolution(t *testing.T) {
|
||||
return *Node(NodeName("node-name-bar")), nil, nil
|
||||
},
|
||||
}
|
||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
||||
cli := test.NewFakeCli(apiClient)
|
||||
tasks := []swarm.Task{
|
||||
*Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
|
||||
}
|
||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }} {{ .Node }}")
|
||||
assert.NoError(t, err)
|
||||
actual := buf.String()
|
||||
expected := golden.Get(t, []byte(actual), "task-print-with-resolution.golden")
|
||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-resolution.golden")
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,3 +1,3 @@
|
||||
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
|
||||
id-foo service-name-foo.1 myimage:mytag node-name-bar Ready Failed 2 hours ago
|
||||
id-bar \_ service-name-foo.1 myimage:mytag node-name-bar Ready Failed 2 hours ago
|
||||
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
|
||||
id-foo service-name-foo.1 myimage:mytag node-name-bar Ready Failed 2 hours ago
|
||||
id-bar \_ service-name-foo.1 myimage:mytag node-name-bar Ready Failed 2 hours ago
|
||||
|
||||
Reference in New Issue
Block a user