github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/network/client_test.go (about)

     1  package network
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/docker/docker/api/types"
     7  	"github.com/docker/docker/api/types/network"
     8  	"github.com/docker/docker/client"
     9  )
    10  
    11  type fakeClient struct {
    12  	client.Client
    13  	networkCreateFunc     func(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)
    14  	networkConnectFunc    func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error
    15  	networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error
    16  	networkListFunc       func(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
    17  }
    18  
    19  func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
    20  	if c.networkCreateFunc != nil {
    21  		return c.networkCreateFunc(ctx, name, options)
    22  	}
    23  	return types.NetworkCreateResponse{}, nil
    24  }
    25  
    26  func (c *fakeClient) NetworkConnect(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
    27  	if c.networkConnectFunc != nil {
    28  		return c.networkConnectFunc(ctx, networkID, container, config)
    29  	}
    30  	return nil
    31  }
    32  
    33  func (c *fakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error {
    34  	if c.networkDisconnectFunc != nil {
    35  		return c.networkDisconnectFunc(ctx, networkID, container, force)
    36  	}
    37  	return nil
    38  }
    39  
    40  func (c *fakeClient) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
    41  	if c.networkListFunc != nil {
    42  		return c.networkListFunc(ctx, options)
    43  	}
    44  	return []types.NetworkResource{}, nil
    45  }