github.com/thajeztah/cli@v0.0.0-20240223162942-dc6bfac81a8b/cli/command/plugin/client_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/filters"
     9  	"github.com/docker/docker/api/types/system"
    10  	"github.com/docker/docker/client"
    11  )
    12  
    13  type fakeClient struct {
    14  	client.Client
    15  	pluginCreateFunc  func(createContext io.Reader, createOptions types.PluginCreateOptions) error
    16  	pluginDisableFunc func(name string, disableOptions types.PluginDisableOptions) error
    17  	pluginEnableFunc  func(name string, options types.PluginEnableOptions) error
    18  	pluginRemoveFunc  func(name string, options types.PluginRemoveOptions) error
    19  	pluginInstallFunc func(name string, options types.PluginInstallOptions) (io.ReadCloser, error)
    20  	pluginListFunc    func(filter filters.Args) (types.PluginsListResponse, error)
    21  	pluginInspectFunc func(name string) (*types.Plugin, []byte, error)
    22  }
    23  
    24  func (c *fakeClient) PluginCreate(_ context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error {
    25  	if c.pluginCreateFunc != nil {
    26  		return c.pluginCreateFunc(createContext, createOptions)
    27  	}
    28  	return nil
    29  }
    30  
    31  func (c *fakeClient) PluginEnable(_ context.Context, name string, enableOptions types.PluginEnableOptions) error {
    32  	if c.pluginEnableFunc != nil {
    33  		return c.pluginEnableFunc(name, enableOptions)
    34  	}
    35  	return nil
    36  }
    37  
    38  func (c *fakeClient) PluginDisable(_ context.Context, name string, disableOptions types.PluginDisableOptions) error {
    39  	if c.pluginDisableFunc != nil {
    40  		return c.pluginDisableFunc(name, disableOptions)
    41  	}
    42  	return nil
    43  }
    44  
    45  func (c *fakeClient) PluginRemove(_ context.Context, name string, removeOptions types.PluginRemoveOptions) error {
    46  	if c.pluginRemoveFunc != nil {
    47  		return c.pluginRemoveFunc(name, removeOptions)
    48  	}
    49  	return nil
    50  }
    51  
    52  func (c *fakeClient) PluginInstall(_ context.Context, name string, installOptions types.PluginInstallOptions) (io.ReadCloser, error) {
    53  	if c.pluginInstallFunc != nil {
    54  		return c.pluginInstallFunc(name, installOptions)
    55  	}
    56  	return nil, nil
    57  }
    58  
    59  func (c *fakeClient) PluginList(_ context.Context, filter filters.Args) (types.PluginsListResponse, error) {
    60  	if c.pluginListFunc != nil {
    61  		return c.pluginListFunc(filter)
    62  	}
    63  
    64  	return types.PluginsListResponse{}, nil
    65  }
    66  
    67  func (c *fakeClient) PluginInspectWithRaw(_ context.Context, name string) (*types.Plugin, []byte, error) {
    68  	if c.pluginInspectFunc != nil {
    69  		return c.pluginInspectFunc(name)
    70  	}
    71  
    72  	return nil, nil, nil
    73  }
    74  
    75  func (c *fakeClient) Info(context.Context) (system.Info, error) {
    76  	return system.Info{}, nil
    77  }