mirror of https://github.com/docker/cli.git
TestStackServicesErrors: use sub-tests, and return tasks
This also sets the services to have a Mode set, otherwise they would be invalid. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
962015b057
commit
228e0f5e76
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli/config/configfile"
|
"github.com/docker/cli/cli/config/configfile"
|
||||||
"github.com/docker/cli/internal/test"
|
"github.com/docker/cli/internal/test"
|
||||||
|
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/cli/internal/test/builders"
|
. "github.com/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
@ -35,17 +36,20 @@ func TestStackServicesErrors(t *testing.T) {
|
||||||
{
|
{
|
||||||
args: []string{"foo"},
|
args: []string{"foo"},
|
||||||
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
return []swarm.Service{*Service()}, nil
|
return []swarm.Service{*Service(GlobalService())}, nil
|
||||||
},
|
},
|
||||||
nodeListFunc: func(options types.NodeListOptions) ([]swarm.Node, error) {
|
nodeListFunc: func(options types.NodeListOptions) ([]swarm.Node, error) {
|
||||||
return nil, errors.Errorf("error getting nodes")
|
return nil, errors.Errorf("error getting nodes")
|
||||||
},
|
},
|
||||||
|
taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
|
||||||
|
return []swarm.Task{*Task()}, nil
|
||||||
|
},
|
||||||
expectedError: "error getting nodes",
|
expectedError: "error getting nodes",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
args: []string{"foo"},
|
args: []string{"foo"},
|
||||||
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
return []swarm.Service{*Service()}, nil
|
return []swarm.Service{*Service(GlobalService())}, nil
|
||||||
},
|
},
|
||||||
taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
|
taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
|
||||||
return nil, errors.Errorf("error getting tasks")
|
return nil, errors.Errorf("error getting tasks")
|
||||||
|
@ -65,6 +69,8 @@ func TestStackServicesErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
t.Run(tc.expectedError, func(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
serviceListFunc: tc.serviceListFunc,
|
serviceListFunc: tc.serviceListFunc,
|
||||||
nodeListFunc: tc.nodeListFunc,
|
nodeListFunc: tc.nodeListFunc,
|
||||||
|
@ -77,6 +83,7 @@ func TestStackServicesErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue