github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/cli/command/swarm/client_test.go (about)

     1  package swarm
     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  	swarmInitFunc         func() (string, error)
    15  	swarmInspectFunc      func() (swarm.Swarm, error)
    16  	nodeInspectFunc       func() (swarm.Node, []byte, error)
    17  	swarmGetUnlockKeyFunc func() (types.SwarmUnlockKeyResponse, error)
    18  	swarmJoinFunc         func() error
    19  	swarmLeaveFunc        func() error
    20  	swarmUpdateFunc       func(swarm swarm.Spec, flags swarm.UpdateFlags) error
    21  	swarmUnlockFunc       func(req swarm.UnlockRequest) error
    22  }
    23  
    24  func (cli *fakeClient) Info(ctx context.Context) (types.Info, error) {
    25  	if cli.infoFunc != nil {
    26  		return cli.infoFunc()
    27  	}
    28  	return types.Info{}, nil
    29  }
    30  
    31  func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, ref string) (swarm.Node, []byte, error) {
    32  	if cli.nodeInspectFunc != nil {
    33  		return cli.nodeInspectFunc()
    34  	}
    35  	return swarm.Node{}, []byte{}, nil
    36  }
    37  
    38  func (cli *fakeClient) SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error) {
    39  	if cli.swarmInitFunc != nil {
    40  		return cli.swarmInitFunc()
    41  	}
    42  	return "", nil
    43  }
    44  
    45  func (cli *fakeClient) SwarmInspect(ctx context.Context) (swarm.Swarm, error) {
    46  	if cli.swarmInspectFunc != nil {
    47  		return cli.swarmInspectFunc()
    48  	}
    49  	return swarm.Swarm{}, nil
    50  }
    51  
    52  func (cli *fakeClient) SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error) {
    53  	if cli.swarmGetUnlockKeyFunc != nil {
    54  		return cli.swarmGetUnlockKeyFunc()
    55  	}
    56  	return types.SwarmUnlockKeyResponse{}, nil
    57  }
    58  
    59  func (cli *fakeClient) SwarmJoin(ctx context.Context, req swarm.JoinRequest) error {
    60  	if cli.swarmJoinFunc != nil {
    61  		return cli.swarmJoinFunc()
    62  	}
    63  	return nil
    64  }
    65  
    66  func (cli *fakeClient) SwarmLeave(ctx context.Context, force bool) error {
    67  	if cli.swarmLeaveFunc != nil {
    68  		return cli.swarmLeaveFunc()
    69  	}
    70  	return nil
    71  }
    72  
    73  func (cli *fakeClient) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error {
    74  	if cli.swarmUpdateFunc != nil {
    75  		return cli.swarmUpdateFunc(swarm, flags)
    76  	}
    77  	return nil
    78  }
    79  
    80  func (cli *fakeClient) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error {
    81  	if cli.swarmUnlockFunc != nil {
    82  		return cli.swarmUnlockFunc(req)
    83  	}
    84  	return nil
    85  }