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

     1  package secret
     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  	secretCreateFunc  func(swarm.SecretSpec) (types.SecretCreateResponse, error)
    14  	secretInspectFunc func(string) (swarm.Secret, []byte, error)
    15  	secretListFunc    func(types.SecretListOptions) ([]swarm.Secret, error)
    16  	secretRemoveFunc  func(string) error
    17  }
    18  
    19  func (c *fakeClient) SecretCreate(ctx context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) {
    20  	if c.secretCreateFunc != nil {
    21  		return c.secretCreateFunc(spec)
    22  	}
    23  	return types.SecretCreateResponse{}, nil
    24  }
    25  
    26  func (c *fakeClient) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
    27  	if c.secretInspectFunc != nil {
    28  		return c.secretInspectFunc(id)
    29  	}
    30  	return swarm.Secret{}, nil, nil
    31  }
    32  
    33  func (c *fakeClient) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
    34  	if c.secretListFunc != nil {
    35  		return c.secretListFunc(options)
    36  	}
    37  	return []swarm.Secret{}, nil
    38  }
    39  
    40  func (c *fakeClient) SecretRemove(ctx context.Context, name string) error {
    41  	if c.secretRemoveFunc != nil {
    42  		return c.secretRemoveFunc(name)
    43  	}
    44  	return nil
    45  }