github.com/xeptore/docker-cli@v20.10.14+incompatible/cli/command/node/client_test.go (about) 1 package node 2 3 import ( 4 "context" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/api/types/swarm" 8 "github.com/docker/docker/client" 9 ) 10 11 type fakeClient struct { 12 client.Client 13 infoFunc func() (types.Info, error) 14 nodeInspectFunc func() (swarm.Node, []byte, error) 15 nodeListFunc func() ([]swarm.Node, error) 16 nodeRemoveFunc func() error 17 nodeUpdateFunc func(nodeID string, version swarm.Version, node swarm.NodeSpec) error 18 taskInspectFunc func(taskID string) (swarm.Task, []byte, error) 19 taskListFunc func(options types.TaskListOptions) ([]swarm.Task, error) 20 serviceInspectFunc func(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) 21 } 22 23 func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) { 24 if cli.nodeInspectFunc != nil { 25 return cli.nodeInspectFunc() 26 } 27 return swarm.Node{}, []byte{}, nil 28 } 29 30 func (cli *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) { 31 if cli.nodeListFunc != nil { 32 return cli.nodeListFunc() 33 } 34 return []swarm.Node{}, nil 35 } 36 37 func (cli *fakeClient) NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error { 38 if cli.nodeRemoveFunc != nil { 39 return cli.nodeRemoveFunc() 40 } 41 return nil 42 } 43 44 func (cli *fakeClient) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error { 45 if cli.nodeUpdateFunc != nil { 46 return cli.nodeUpdateFunc(nodeID, version, node) 47 } 48 return nil 49 } 50 51 func (cli *fakeClient) Info(ctx context.Context) (types.Info, error) { 52 if cli.infoFunc != nil { 53 return cli.infoFunc() 54 } 55 return types.Info{}, nil 56 } 57 58 func (cli *fakeClient) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) { 59 if cli.taskInspectFunc != nil { 60 return cli.taskInspectFunc(taskID) 61 } 62 return swarm.Task{}, []byte{}, nil 63 } 64 65 func (cli *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) { 66 if cli.taskListFunc != nil { 67 return cli.taskListFunc(options) 68 } 69 return []swarm.Task{}, nil 70 } 71 72 func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) { 73 if cli.serviceInspectFunc != nil { 74 return cli.serviceInspectFunc(ctx, serviceID, opts) 75 } 76 return swarm.Service{}, []byte{}, nil 77 }