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
|
2024-09-12 13:18:46 -04:00
|
|
|
imageSaveFunc func(images []string, options image.SaveOptions) (io.ReadCloser, error)
|
2024-01-24 08:32:07 -05:00
|
|
|
imageRemoveFunc func(image string, options image.RemoveOptions) ([]image.DeleteResponse, error)
|
|
|
|
imagePushFunc func(ref string, options image.PushOptions) (io.ReadCloser, error)
|
2023-07-14 17:42:40 -04:00
|
|
|
infoFunc func() (system.Info, error)
|
2024-01-24 08:32:07 -05:00
|
|
|
imagePullFunc func(ref string, options image.PullOptions) (io.ReadCloser, error)
|
2024-06-09 07:54:37 -04:00
|
|
|
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
|
2024-09-12 13:18:46 -04:00
|
|
|
imageLoadFunc func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error)
|
2024-01-24 08:32:07 -05:00
|
|
|
imageListFunc func(options image.ListOptions) ([]image.Summary, error)
|
2024-07-03 09:35:44 -04:00
|
|
|
imageInspectFunc func(img string) (image.InspectResponse, []byte, error)
|
2024-06-09 07:54:37 -04:00
|
|
|
imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
|
2024-09-12 13:18:46 -04:00
|
|
|
imageHistoryFunc func(img string, options image.HistoryOptions) ([]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
|
|
|
}
|
|
|
|
|
2023-11-20 11:38:50 -05:00
|
|
|
func (cli *fakeClient) ImageTag(_ context.Context, img, ref string) error {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageTagFunc != nil {
|
2023-11-20 11:38:50 -05:00
|
|
|
return cli.imageTagFunc(img, ref)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-12 13:18:46 -04:00
|
|
|
func (cli *fakeClient) ImageSave(_ context.Context, images []string, options image.SaveOptions) (io.ReadCloser, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageSaveFunc != nil {
|
2024-09-12 13:18:46 -04:00
|
|
|
return cli.imageSaveFunc(images, options)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
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,
|
2024-01-24 08:32:07 -05:00
|
|
|
options image.RemoveOptions,
|
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
|
|
|
}
|
|
|
|
|
2024-01-24 08:32:07 -05:00
|
|
|
func (cli *fakeClient) ImagePush(_ context.Context, ref string, options image.PushOptions) (io.ReadCloser, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-01-24 08:32:07 -05:00
|
|
|
func (cli *fakeClient) ImagePull(_ context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imagePullFunc != nil {
|
2024-07-03 10:36:56 -04:00
|
|
|
return cli.imagePullFunc(ref, options)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
2022-02-25 07:10:34 -05:00
|
|
|
return io.NopCloser(strings.NewReader("")), nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
2024-06-09 07:54:37 -04:00
|
|
|
func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter filters.Args) (image.PruneReport, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imagesPruneFunc != nil {
|
|
|
|
return cli.imagesPruneFunc(pruneFilter)
|
|
|
|
}
|
2024-06-09 07:54:37 -04:00
|
|
|
return image.PruneReport{}, nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
2024-09-12 13:18:46 -04:00
|
|
|
func (cli *fakeClient) ImageLoad(_ context.Context, input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageLoadFunc != nil {
|
2024-09-12 13:18:46 -04:00
|
|
|
return cli.imageLoadFunc(input, options)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
2024-06-09 07:54:37 -04:00
|
|
|
return image.LoadResponse{}, nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
2024-01-24 08:32:07 -05:00
|
|
|
func (cli *fakeClient) ImageList(_ context.Context, options image.ListOptions) ([]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
|
|
|
}
|
|
|
|
|
2024-07-03 09:35:44 -04:00
|
|
|
func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, img string) (image.InspectResponse, []byte, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageInspectFunc != nil {
|
2023-11-20 11:38:50 -05:00
|
|
|
return cli.imageInspectFunc(img)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
2024-07-03 09:35:44 -04:00
|
|
|
return image.InspectResponse{}, nil, nil
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
|
2024-06-09 07:54:37 -04:00
|
|
|
func (cli *fakeClient) ImageImport(_ context.Context, source image.ImportSource, ref string,
|
2024-01-24 08:32:07 -05:00
|
|
|
options image.ImportOptions,
|
2022-09-29 11:21:51 -04:00
|
|
|
) (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
|
|
|
}
|
|
|
|
|
2024-09-12 13:18:46 -04:00
|
|
|
func (cli *fakeClient) ImageHistory(_ context.Context, img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) {
|
2017-03-30 20:21:14 -04:00
|
|
|
if cli.imageHistoryFunc != nil {
|
2024-09-12 13:18:46 -04:00
|
|
|
return cli.imageHistoryFunc(img, options)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
return []image.HistoryResponseItem{{ID: img, Created: time.Now().Unix()}}, nil
|
|
|
|
}
|
2017-06-21 15:13:44 -04:00
|
|
|
|
2023-11-20 11:38:50 -05:00
|
|
|
func (cli *fakeClient) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
2017-06-21 15:13:44 -04:00
|
|
|
if cli.imageBuildFunc != nil {
|
2023-11-20 11:38:50 -05:00
|
|
|
return cli.imageBuildFunc(ctx, buildContext, options)
|
2017-06-21 15:13:44 -04:00
|
|
|
}
|
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
|
|
|
}
|