129 lines
6.7 KiB
Go
129 lines
6.7 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package mocks
|
|
|
|
import (
|
|
"context"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/api/types/network"
|
|
"github.com/docker/docker/api/types/volume"
|
|
"github.com/docker/docker/api/types/image"
|
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
"io"
|
|
)
|
|
|
|
type MockContainerClient struct {
|
|
InjectContainerStart func(ctx context.Context, containerID string, options container.StartOptions) error
|
|
InjectContainerCreate func(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
|
|
InjectNetworkCreate func(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error)
|
|
InjectNetworkList func(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
|
|
InjectNetworkInspect func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error)
|
|
InjectContainerList func(context.Context, container.ListOptions) ([]types.Container, error)
|
|
InjectContainerInspect func(context.Context, string) (types.ContainerJSON, error)
|
|
InjectContainerRemove func(context.Context, string, container.RemoveOptions) error
|
|
InjectContainerStop func(context.Context, string, container.StopOptions) error
|
|
InjectContainerWait func(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
|
|
InjectContainerLogs func(ctx context.Context, containerID string, options container.LogsOptions) (io.ReadCloser, error)
|
|
InjectImagePull func(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
|
|
InjectImagePush func(ctx context.Context, image string, options image.PushOptions) (io.ReadCloser, error)
|
|
InjectImageInspectWithRaw func(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)
|
|
InjectImageRemove func(ctx context.Context, imageID string, options image.RemoveOptions) ([]image.DeleteResponse, error)
|
|
InjectImageBuild func(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
|
InjectVolumeCreate func(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
|
|
InjectVolumeList func(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
|
|
InjectVolumeInspect func(ctx context.Context, volumeID string) (volume.Volume, error)
|
|
InjectVolumeRemove func(ctx context.Context, volumeID string, force bool) (error)
|
|
InjectClose func() error
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerWait(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error) {
|
|
return m.InjectContainerWait(ctx, containerID, condition)
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerLogs(ctx context.Context, containerID string, options container.LogsOptions) (io.ReadCloser, error) {
|
|
return m.InjectContainerLogs(ctx, containerID, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ImageRemove(ctx context.Context, imageID string, options image.RemoveOptions) ([]image.DeleteResponse, error) {
|
|
return m.InjectImageRemove(ctx, imageID, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error) {
|
|
return m.InjectImagePull(ctx, refStr, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ImagePush(ctx context.Context, image string, options image.PushOptions) (io.ReadCloser, error) {
|
|
return m.InjectImagePush(ctx, image, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
|
return m.InjectImageBuild(ctx, buildContext, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) {
|
|
return m.InjectImageInspectWithRaw(ctx, imageID)
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error) {
|
|
return m.InjectContainerCreate(ctx, config, hostConfig, networkingConfig, platform, containerName)
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error {
|
|
if m.InjectContainerStart == nil {
|
|
return nil
|
|
}
|
|
return m.InjectContainerStart(ctx, containerID, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
|
|
return m.InjectContainerList(ctx, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) {
|
|
return m.InjectContainerInspect(ctx, containerID)
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error {
|
|
return m.InjectContainerRemove(ctx, containerID, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error {
|
|
return m.InjectContainerStop(ctx, containerID, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) Close() error {
|
|
if m.InjectClose == nil {
|
|
return nil
|
|
}
|
|
return m.InjectClose()
|
|
}
|
|
|
|
func (m *MockContainerClient) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) {
|
|
return m.InjectNetworkCreate(ctx, name, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
|
return m.InjectNetworkList(ctx, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) {
|
|
return m.InjectNetworkInspect(ctx, networkID, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error) {
|
|
return m.InjectVolumeCreate(ctx, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) {
|
|
return m.InjectVolumeList(ctx, options)
|
|
}
|
|
|
|
func (m *MockContainerClient) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) {
|
|
return m.InjectVolumeInspect(ctx, volumeID)
|
|
}
|
|
|
|
func (m *MockContainerClient) VolumeRemove(ctx context.Context, volumeID string, force bool) (error) {
|
|
return m.InjectVolumeRemove(ctx, volumeID, force)
|
|
}
|