2017-03-30 20:21:14 -04:00
|
|
|
package image
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2017-03-30 20:21:14 -04:00
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/api/types/image"
|
2023-07-14 17:42:40 -04:00
|
|
|
"github.com/docker/docker/api/types/system"
|
2017-05-08 13:51:30 -04:00
|
|
|
"github.com/docker/docker/client"
|
2017-03-30 20:21:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeClient struct {
|
|
|
|
client.Client
|
|
|
|
imageTagFunc func(string, string) error
|
|
|
|
imageSaveFunc func(images []string) (io.ReadCloser, error)
|
2023-10-13 14:34:32 -04:00
|
|
|
imageRemoveFunc func(image string, options types.ImageRemoveOptions) ([]image.DeleteResponse, error)
|
2017-03-30 20:21:14 -04:00
|
|
|
imagePushFunc func(ref string, options types.ImagePushOptions) (io.ReadCloser, error)
|
2023-07-14 17:42:40 -04:00
|
|
|
infoFunc func() (system.Info, error)
|
2017-03-30 20:21:14 -04:00
|
|
|
imagePullFunc func(ref string, options types.ImagePullOptions) (io.ReadCloser, error)
|
|
|
|
imagesPruneFunc func(pruneFilter filters.Args) (types.ImagesPruneReport, error)
|
|
|
|
imageLoadFunc func(input io.Reader, quiet bool) (types.ImageLoadResponse, error)
|
2023-10-13 14:34:32 -04:00
|
|
|
imageListFunc func(options types.ImageListOptions) ([]image.Summary, error)
|
2017-03-30 20:21:14 -04:00
|
|
|
imageInspectFunc func(image string) (types.ImageInspect, []byte, error)
|
|
|
|
imageImportFunc func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error)
|
|
|
|
imageHistoryFunc func(image string) ([]image.HistoryResponseItem, error)
|
2017-06-21 15:13:44 -04:00
|
|
|
imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImageTag(_ context.Context, image, ref string) error {
|
|
|
|
if cli.imageTagFunc != nil {
|
|
|
|
return cli.imageTagFunc(image, ref)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImageSave(_ context.Context, images []string) (io.ReadCloser, error) {
|
|
|
|
if cli.imageSaveFunc != nil {
|
|
|
|
return cli.imageSaveFunc(images)
|
|
|
|
}
|
2022-02-25 07:10:34 -05:00
|
|
|
return io.NopCloser(strings.NewReader("")), nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
2023-10-13 14:34:32 -04:00
|
|
|
func (cli *fakeClient) ImageRemove(_ context.Context, img string,
|
2022-09-29 11:21:51 -04:00
|
|
|
options types.ImageRemoveOptions,
|
2023-10-13 14:34:32 -04:00
|
|
|
) ([]image.DeleteResponse, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageRemoveFunc != nil {
|
2023-10-13 14:34:32 -04:00
|
|
|
return cli.imageRemoveFunc(img, options)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
2023-10-13 14:34:32 -04:00
|
|
|
return []image.DeleteResponse{}, nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImagePush(_ context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
|
|
|
if cli.imagePushFunc != nil {
|
|
|
|
return cli.imagePushFunc(ref, options)
|
|
|
|
}
|
2022-02-25 07:10:34 -05:00
|
|
|
return io.NopCloser(strings.NewReader("")), nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
2023-07-14 17:42:40 -04:00
|
|
|
func (cli *fakeClient) Info(_ context.Context) (system.Info, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.infoFunc != nil {
|
|
|
|
return cli.infoFunc()
|
|
|
|
}
|
2023-07-14 17:42:40 -04:00
|
|
|
return system.Info{}, nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImagePull(_ context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
|
|
|
|
if cli.imagePullFunc != nil {
|
|
|
|
cli.imagePullFunc(ref, options)
|
|
|
|
}
|
2022-02-25 07:10:34 -05:00
|
|
|
return io.NopCloser(strings.NewReader("")), nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter filters.Args) (types.ImagesPruneReport, error) {
|
|
|
|
if cli.imagesPruneFunc != nil {
|
|
|
|
return cli.imagesPruneFunc(pruneFilter)
|
|
|
|
}
|
|
|
|
return types.ImagesPruneReport{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImageLoad(_ context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
|
|
|
|
if cli.imageLoadFunc != nil {
|
|
|
|
return cli.imageLoadFunc(input, quiet)
|
|
|
|
}
|
|
|
|
return types.ImageLoadResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:34:32 -04:00
|
|
|
func (cli *fakeClient) ImageList(_ context.Context, options types.ImageListOptions) ([]image.Summary, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageListFunc != nil {
|
|
|
|
return cli.imageListFunc(options)
|
|
|
|
}
|
2023-10-13 14:34:32 -04:00
|
|
|
return []image.Summary{}, nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, image string) (types.ImageInspect, []byte, error) {
|
|
|
|
if cli.imageInspectFunc != nil {
|
|
|
|
return cli.imageInspectFunc(image)
|
|
|
|
}
|
|
|
|
return types.ImageInspect{}, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImageImport(_ context.Context, source types.ImageImportSource, ref string,
|
2022-09-29 11:21:51 -04:00
|
|
|
options types.ImageImportOptions,
|
|
|
|
) (io.ReadCloser, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageImportFunc != nil {
|
|
|
|
return cli.imageImportFunc(source, ref, options)
|
|
|
|
}
|
2022-02-25 07:10:34 -05:00
|
|
|
return io.NopCloser(strings.NewReader("")), nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImageHistory(_ context.Context, img string) ([]image.HistoryResponseItem, error) {
|
|
|
|
if cli.imageHistoryFunc != nil {
|
|
|
|
return cli.imageHistoryFunc(img)
|
|
|
|
}
|
|
|
|
return []image.HistoryResponseItem{{ID: img, Created: time.Now().Unix()}}, nil
|
|
|
|
}
|
2017-06-21 15:13:44 -04:00
|
|
|
|
|
|
|
func (cli *fakeClient) ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
|
|
|
if cli.imageBuildFunc != nil {
|
|
|
|
return cli.imageBuildFunc(ctx, context, options)
|
|
|
|
}
|
2022-02-25 07:10:34 -05:00
|
|
|
return types.ImageBuildResponse{Body: io.NopCloser(strings.NewReader(""))}, nil
|
2017-06-21 15:13:44 -04:00
|
|
|
}
|