mirror of https://github.com/docker/cli.git
Update stack and task command tests to new golden
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
4c62d7288f
commit
1dd742eac8
|
@ -1,7 +1,6 @@
|
||||||
package stack
|
package stack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -61,8 +60,7 @@ func TestListErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListWithFormat(t *testing.T) {
|
func TestListWithFormat(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
cmd := newListCommand(test.NewFakeCliWithOutput(&fakeClient{
|
|
||||||
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
return []swarm.Service{
|
return []swarm.Service{
|
||||||
*Service(
|
*Service(
|
||||||
|
@ -71,17 +69,15 @@ func TestListWithFormat(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
)}, nil
|
)}, nil
|
||||||
},
|
},
|
||||||
}, buf))
|
})
|
||||||
|
cmd := newListCommand(cli)
|
||||||
cmd.Flags().Set("format", "{{ .Name }}")
|
cmd.Flags().Set("format", "{{ .Name }}")
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-list-with-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-list-with-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListWithoutFormat(t *testing.T) {
|
func TestListWithoutFormat(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
cmd := newListCommand(test.NewFakeCliWithOutput(&fakeClient{
|
|
||||||
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
return []swarm.Service{
|
return []swarm.Service{
|
||||||
*Service(
|
*Service(
|
||||||
|
@ -90,11 +86,10 @@ func TestListWithoutFormat(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
)}, nil
|
)}, nil
|
||||||
},
|
},
|
||||||
}, buf))
|
})
|
||||||
|
cmd := newListCommand(cli)
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-list-without-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-list-without-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListOrder(t *testing.T) {
|
func TestListOrder(t *testing.T) {
|
||||||
|
@ -140,15 +135,13 @@ func TestListOrder(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, uc := range usecases {
|
for _, uc := range usecases {
|
||||||
buf := new(bytes.Buffer)
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
cmd := newListCommand(test.NewFakeCliWithOutput(&fakeClient{
|
|
||||||
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
return uc.swarmServices, nil
|
return uc.swarmServices, nil
|
||||||
},
|
},
|
||||||
}, buf))
|
})
|
||||||
|
cmd := newListCommand(cli)
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), uc.golden)
|
||||||
expected := golden.Get(t, []byte(actual), uc.golden)
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -75,9 +75,7 @@ func TestStackPsWithQuietOption(t *testing.T) {
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
cmd.Flags().Set("quiet", "true")
|
cmd.Flags().Set("quiet", "true")
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-quiet-option.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-ps-with-quiet-option.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +90,7 @@ func TestStackPsWithNoTruncOption(t *testing.T) {
|
||||||
cmd.Flags().Set("no-trunc", "true")
|
cmd.Flags().Set("no-trunc", "true")
|
||||||
cmd.Flags().Set("format", "{{ .ID }}")
|
cmd.Flags().Set("format", "{{ .ID }}")
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-trunc-option.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-ps-with-no-trunc-option.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStackPsWithNoResolveOption(t *testing.T) {
|
func TestStackPsWithNoResolveOption(t *testing.T) {
|
||||||
|
@ -113,9 +109,7 @@ func TestStackPsWithNoResolveOption(t *testing.T) {
|
||||||
cmd.Flags().Set("no-resolve", "true")
|
cmd.Flags().Set("no-resolve", "true")
|
||||||
cmd.Flags().Set("format", "{{ .Node }}")
|
cmd.Flags().Set("format", "{{ .Node }}")
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-resolve-option.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-ps-with-no-resolve-option.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStackPsWithFormat(t *testing.T) {
|
func TestStackPsWithFormat(t *testing.T) {
|
||||||
|
@ -128,9 +122,7 @@ func TestStackPsWithFormat(t *testing.T) {
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
cmd.Flags().Set("format", "{{ .Name }}")
|
cmd.Flags().Set("format", "{{ .Name }}")
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-ps-with-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStackPsWithConfigFormat(t *testing.T) {
|
func TestStackPsWithConfigFormat(t *testing.T) {
|
||||||
|
@ -145,9 +137,7 @@ func TestStackPsWithConfigFormat(t *testing.T) {
|
||||||
cmd := newPsCommand(cli)
|
cmd := newPsCommand(cli)
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-config-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-ps-with-config-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStackPsWithoutFormat(t *testing.T) {
|
func TestStackPsWithoutFormat(t *testing.T) {
|
||||||
|
@ -169,7 +159,5 @@ func TestStackPsWithoutFormat(t *testing.T) {
|
||||||
cmd := newPsCommand(cli)
|
cmd := newPsCommand(cli)
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-without-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-ps-without-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -103,9 +103,7 @@ func TestStackServicesWithQuietOption(t *testing.T) {
|
||||||
cmd.Flags().Set("quiet", "true")
|
cmd.Flags().Set("quiet", "true")
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-quiet-option.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-services-with-quiet-option.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStackServicesWithFormat(t *testing.T) {
|
func TestStackServicesWithFormat(t *testing.T) {
|
||||||
|
@ -120,9 +118,7 @@ func TestStackServicesWithFormat(t *testing.T) {
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
cmd.Flags().Set("format", "{{ .Name }}")
|
cmd.Flags().Set("format", "{{ .Name }}")
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-services-with-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStackServicesWithConfigFormat(t *testing.T) {
|
func TestStackServicesWithConfigFormat(t *testing.T) {
|
||||||
|
@ -139,9 +135,7 @@ func TestStackServicesWithConfigFormat(t *testing.T) {
|
||||||
cmd := newServicesCommand(cli)
|
cmd := newServicesCommand(cli)
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-config-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-services-with-config-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStackServicesWithoutFormat(t *testing.T) {
|
func TestStackServicesWithoutFormat(t *testing.T) {
|
||||||
|
@ -164,7 +158,5 @@ func TestStackServicesWithoutFormat(t *testing.T) {
|
||||||
cmd := newServicesCommand(cli)
|
cmd := newServicesCommand(cli)
|
||||||
cmd.SetArgs([]string{"foo"})
|
cmd.SetArgs([]string{"foo"})
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), "stack-services-without-format.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "stack-services-without-format.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package task
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -13,8 +12,7 @@ import (
|
||||||
. "github.com/docker/cli/cli/internal/test/builders"
|
. "github.com/docker/cli/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,75 +20,60 @@ func TestTaskPrintWithQuietOption(t *testing.T) {
|
||||||
quiet := true
|
quiet := true
|
||||||
trunc := false
|
trunc := false
|
||||||
noResolve := true
|
noResolve := true
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
apiClient := &fakeClient{}
|
apiClient := &fakeClient{}
|
||||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
cli := test.NewFakeCli(apiClient)
|
||||||
tasks := []swarm.Task{
|
tasks := []swarm.Task{*Task(TaskID("id-foo"))}
|
||||||
*Task(TaskID("id-foo")),
|
|
||||||
}
|
|
||||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey)
|
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-quiet-option.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "task-print-with-quiet-option.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTaskPrintWithNoTruncOption(t *testing.T) {
|
func TestTaskPrintWithNoTruncOption(t *testing.T) {
|
||||||
quiet := false
|
quiet := false
|
||||||
trunc := false
|
trunc := false
|
||||||
noResolve := true
|
noResolve := true
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
apiClient := &fakeClient{}
|
apiClient := &fakeClient{}
|
||||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
cli := test.NewFakeCli(apiClient)
|
||||||
tasks := []swarm.Task{
|
tasks := []swarm.Task{
|
||||||
*Task(TaskID("id-foo-yov6omdek8fg3k5stosyp2m50")),
|
*Task(TaskID("id-foo-yov6omdek8fg3k5stosyp2m50")),
|
||||||
}
|
}
|
||||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .ID }}")
|
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .ID }}")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-no-trunc-option.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "task-print-with-no-trunc-option.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTaskPrintWithGlobalService(t *testing.T) {
|
func TestTaskPrintWithGlobalService(t *testing.T) {
|
||||||
quiet := false
|
quiet := false
|
||||||
trunc := false
|
trunc := false
|
||||||
noResolve := true
|
noResolve := true
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
apiClient := &fakeClient{}
|
apiClient := &fakeClient{}
|
||||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
cli := test.NewFakeCli(apiClient)
|
||||||
tasks := []swarm.Task{
|
tasks := []swarm.Task{
|
||||||
*Task(TaskServiceID("service-id-foo"), TaskNodeID("node-id-bar"), TaskSlot(0)),
|
*Task(TaskServiceID("service-id-foo"), TaskNodeID("node-id-bar"), TaskSlot(0)),
|
||||||
}
|
}
|
||||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}")
|
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-global-service.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "task-print-with-global-service.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTaskPrintWithReplicatedService(t *testing.T) {
|
func TestTaskPrintWithReplicatedService(t *testing.T) {
|
||||||
quiet := false
|
quiet := false
|
||||||
trunc := false
|
trunc := false
|
||||||
noResolve := true
|
noResolve := true
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
apiClient := &fakeClient{}
|
apiClient := &fakeClient{}
|
||||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
cli := test.NewFakeCli(apiClient)
|
||||||
tasks := []swarm.Task{
|
tasks := []swarm.Task{
|
||||||
*Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
|
*Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
|
||||||
}
|
}
|
||||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}")
|
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-replicated-service.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "task-print-with-replicated-service.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTaskPrintWithIndentation(t *testing.T) {
|
func TestTaskPrintWithIndentation(t *testing.T) {
|
||||||
quiet := false
|
quiet := false
|
||||||
trunc := false
|
trunc := false
|
||||||
noResolve := false
|
noResolve := false
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
apiClient := &fakeClient{
|
apiClient := &fakeClient{
|
||||||
serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
||||||
return *Service(ServiceName("service-name-foo")), nil, nil
|
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
|
return *Node(NodeName("node-name-bar")), nil, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
cli := test.NewFakeCli(apiClient)
|
||||||
tasks := []swarm.Task{
|
tasks := []swarm.Task{
|
||||||
*Task(
|
*Task(
|
||||||
TaskID("id-foo"),
|
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)
|
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-indentation.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "task-print-with-indentation.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTaskPrintWithResolution(t *testing.T) {
|
func TestTaskPrintWithResolution(t *testing.T) {
|
||||||
quiet := false
|
quiet := false
|
||||||
trunc := false
|
trunc := false
|
||||||
noResolve := false
|
noResolve := false
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
apiClient := &fakeClient{
|
apiClient := &fakeClient{
|
||||||
serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
||||||
return *Service(ServiceName("service-name-foo")), nil, nil
|
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
|
return *Node(NodeName("node-name-bar")), nil, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cli := test.NewFakeCliWithOutput(apiClient, buf)
|
cli := test.NewFakeCli(apiClient)
|
||||||
tasks := []swarm.Task{
|
tasks := []swarm.Task{
|
||||||
*Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
|
*Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
|
||||||
}
|
}
|
||||||
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }} {{ .Node }}")
|
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }} {{ .Node }}")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), "task-print-with-resolution.golden")
|
||||||
expected := golden.Get(t, []byte(actual), "task-print-with-resolution.golden")
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue