|
| 1 | +package image |
| 2 | + |
| 3 | +import ( |
| 4 | + "io" |
| 5 | + "io/ioutil" |
| 6 | + "strings" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/docker/docker/api/types" |
| 10 | + "github.com/docker/docker/api/types/filters" |
| 11 | + "github.com/docker/docker/api/types/image" |
| 12 | + "github.com/docker/docker/client" |
| 13 | + "golang.org/x/net/context" |
| 14 | +) |
| 15 | + |
| 16 | +type fakeClient struct { |
| 17 | + client.Client |
| 18 | + imageTagFunc func(string, string) error |
| 19 | + imageSaveFunc func(images []string) (io.ReadCloser, error) |
| 20 | + imageRemoveFunc func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) |
| 21 | + imagePushFunc func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) |
| 22 | + infoFunc func() (types.Info, error) |
| 23 | + imagePullFunc func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) |
| 24 | + imagesPruneFunc func(pruneFilter filters.Args) (types.ImagesPruneReport, error) |
| 25 | + imageLoadFunc func(input io.Reader, quiet bool) (types.ImageLoadResponse, error) |
| 26 | + imageListFunc func(options types.ImageListOptions) ([]types.ImageSummary, error) |
| 27 | + imageInspectFunc func(image string) (types.ImageInspect, []byte, error) |
| 28 | + imageImportFunc func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) |
| 29 | + imageHistoryFunc func(image string) ([]image.HistoryResponseItem, error) |
| 30 | +} |
| 31 | + |
| 32 | +func (cli *fakeClient) ImageTag(_ context.Context, image, ref string) error { |
| 33 | + if cli.imageTagFunc != nil { |
| 34 | + return cli.imageTagFunc(image, ref) |
| 35 | + } |
| 36 | + return nil |
| 37 | +} |
| 38 | + |
| 39 | +func (cli *fakeClient) ImageSave(_ context.Context, images []string) (io.ReadCloser, error) { |
| 40 | + if cli.imageSaveFunc != nil { |
| 41 | + return cli.imageSaveFunc(images) |
| 42 | + } |
| 43 | + return ioutil.NopCloser(strings.NewReader("")), nil |
| 44 | +} |
| 45 | + |
| 46 | +func (cli *fakeClient) ImageRemove(_ context.Context, image string, |
| 47 | + options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { |
| 48 | + if cli.imageRemoveFunc != nil { |
| 49 | + return cli.imageRemoveFunc(image, options) |
| 50 | + } |
| 51 | + return []types.ImageDeleteResponseItem{}, nil |
| 52 | +} |
| 53 | + |
| 54 | +func (cli *fakeClient) ImagePush(_ context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error) { |
| 55 | + if cli.imagePushFunc != nil { |
| 56 | + return cli.imagePushFunc(ref, options) |
| 57 | + } |
| 58 | + return ioutil.NopCloser(strings.NewReader("")), nil |
| 59 | +} |
| 60 | + |
| 61 | +func (cli *fakeClient) Info(_ context.Context) (types.Info, error) { |
| 62 | + if cli.infoFunc != nil { |
| 63 | + return cli.infoFunc() |
| 64 | + } |
| 65 | + return types.Info{}, nil |
| 66 | +} |
| 67 | + |
| 68 | +func (cli *fakeClient) ImagePull(_ context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error) { |
| 69 | + if cli.imagePullFunc != nil { |
| 70 | + cli.imagePullFunc(ref, options) |
| 71 | + } |
| 72 | + return ioutil.NopCloser(strings.NewReader("")), nil |
| 73 | +} |
| 74 | + |
| 75 | +func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter filters.Args) (types.ImagesPruneReport, error) { |
| 76 | + if cli.imagesPruneFunc != nil { |
| 77 | + return cli.imagesPruneFunc(pruneFilter) |
| 78 | + } |
| 79 | + return types.ImagesPruneReport{}, nil |
| 80 | +} |
| 81 | + |
| 82 | +func (cli *fakeClient) ImageLoad(_ context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error) { |
| 83 | + if cli.imageLoadFunc != nil { |
| 84 | + return cli.imageLoadFunc(input, quiet) |
| 85 | + } |
| 86 | + return types.ImageLoadResponse{}, nil |
| 87 | +} |
| 88 | + |
| 89 | +func (cli *fakeClient) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) { |
| 90 | + if cli.imageListFunc != nil { |
| 91 | + return cli.imageListFunc(options) |
| 92 | + } |
| 93 | + return []types.ImageSummary{{}}, nil |
| 94 | +} |
| 95 | + |
| 96 | +func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, image string) (types.ImageInspect, []byte, error) { |
| 97 | + if cli.imageInspectFunc != nil { |
| 98 | + return cli.imageInspectFunc(image) |
| 99 | + } |
| 100 | + return types.ImageInspect{}, nil, nil |
| 101 | +} |
| 102 | + |
| 103 | +func (cli *fakeClient) ImageImport(_ context.Context, source types.ImageImportSource, ref string, |
| 104 | + options types.ImageImportOptions) (io.ReadCloser, error) { |
| 105 | + if cli.imageImportFunc != nil { |
| 106 | + return cli.imageImportFunc(source, ref, options) |
| 107 | + } |
| 108 | + return ioutil.NopCloser(strings.NewReader("")), nil |
| 109 | +} |
| 110 | + |
| 111 | +func (cli *fakeClient) ImageHistory(_ context.Context, img string) ([]image.HistoryResponseItem, error) { |
| 112 | + if cli.imageHistoryFunc != nil { |
| 113 | + return cli.imageHistoryFunc(img) |
| 114 | + } |
| 115 | + return []image.HistoryResponseItem{{ID: img, Created: time.Now().Unix()}}, nil |
| 116 | +} |
0 commit comments