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