github.com/xeptore/docker-cli@v20.10.14+incompatible/cli/command/service/client_test.go (about)

     1  package service
     2  
     3  import (
     4  	"context"
     5  
     6  	. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/swarm"
     9  	"github.com/docker/docker/client"
    10  )
    11  
    12  type fakeClient struct {
    13  	client.Client
    14  	serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
    15  	serviceUpdateFunc         func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
    16  	serviceListFunc           func(context.Context, types.ServiceListOptions) ([]swarm.Service, error)
    17  	taskListFunc              func(context.Context, types.TaskListOptions) ([]swarm.Task, error)
    18  	infoFunc                  func(ctx context.Context) (types.Info, error)
    19  	networkInspectFunc        func(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error)
    20  	nodeListFunc              func(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
    21  }
    22  
    23  func (f *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
    24  	if f.nodeListFunc != nil {
    25  		return f.nodeListFunc(ctx, options)
    26  	}
    27  	return nil, nil
    28  }
    29  
    30  func (f *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
    31  	if f.taskListFunc != nil {
    32  		return f.taskListFunc(ctx, options)
    33  	}
    34  	return nil, nil
    35  }
    36  
    37  func (f *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
    38  	if f.serviceInspectWithRawFunc != nil {
    39  		return f.serviceInspectWithRawFunc(ctx, serviceID, options)
    40  	}
    41  
    42  	return *Service(ServiceID(serviceID)), []byte{}, nil
    43  }
    44  
    45  func (f *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
    46  	if f.serviceListFunc != nil {
    47  		return f.serviceListFunc(ctx, options)
    48  	}
    49  
    50  	return nil, nil
    51  }
    52  
    53  func (f *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
    54  	if f.serviceUpdateFunc != nil {
    55  		return f.serviceUpdateFunc(ctx, serviceID, version, service, options)
    56  	}
    57  
    58  	return types.ServiceUpdateResponse{}, nil
    59  }
    60  
    61  func (f *fakeClient) Info(ctx context.Context) (types.Info, error) {
    62  	if f.infoFunc == nil {
    63  		return types.Info{}, nil
    64  	}
    65  	return f.infoFunc(ctx)
    66  }
    67  
    68  func (f *fakeClient) NetworkInspect(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error) {
    69  	if f.networkInspectFunc != nil {
    70  		return f.networkInspectFunc(ctx, networkID, options)
    71  	}
    72  	return types.NetworkResource{}, nil
    73  }
    74  
    75  func newService(id string, name string) swarm.Service {
    76  	return *Service(ServiceID(id), ServiceName(name))
    77  }