github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/cli/command/node/client_test.go (about)

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