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