client_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package node
  2. import (
  3. "github.com/docker/docker/api/types"
  4. "github.com/docker/docker/api/types/swarm"
  5. "github.com/docker/docker/client"
  6. "golang.org/x/net/context"
  7. )
  8. type fakeClient struct {
  9. client.Client
  10. infoFunc func() (types.Info, error)
  11. nodeInspectFunc func() (swarm.Node, []byte, error)
  12. nodeListFunc func() ([]swarm.Node, error)
  13. nodeRemoveFunc func() error
  14. nodeUpdateFunc func(nodeID string, version swarm.Version, node swarm.NodeSpec) error
  15. taskInspectFunc func(taskID string) (swarm.Task, []byte, error)
  16. taskListFunc func(options types.TaskListOptions) ([]swarm.Task, error)
  17. }
  18. func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) {
  19. if cli.nodeInspectFunc != nil {
  20. return cli.nodeInspectFunc()
  21. }
  22. return swarm.Node{}, []byte{}, nil
  23. }
  24. func (cli *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
  25. if cli.nodeListFunc != nil {
  26. return cli.nodeListFunc()
  27. }
  28. return []swarm.Node{}, nil
  29. }
  30. func (cli *fakeClient) NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error {
  31. if cli.nodeRemoveFunc != nil {
  32. return cli.nodeRemoveFunc()
  33. }
  34. return nil
  35. }
  36. func (cli *fakeClient) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error {
  37. if cli.nodeUpdateFunc != nil {
  38. return cli.nodeUpdateFunc(nodeID, version, node)
  39. }
  40. return nil
  41. }
  42. func (cli *fakeClient) Info(ctx context.Context) (types.Info, error) {
  43. if cli.infoFunc != nil {
  44. return cli.infoFunc()
  45. }
  46. return types.Info{}, nil
  47. }
  48. func (cli *fakeClient) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) {
  49. if cli.taskInspectFunc != nil {
  50. return cli.taskInspectFunc(taskID)
  51. }
  52. return swarm.Task{}, []byte{}, nil
  53. }
  54. func (cli *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
  55. if cli.taskListFunc != nil {
  56. return cli.taskListFunc(options)
  57. }
  58. return []swarm.Task{}, nil
  59. }