jx/tests/mocks/container.go

98 lines
5.0 KiB
Go
Raw Normal View History

2024-03-20 19:23:31 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
2024-05-24 05:11:51 +00:00
2024-03-20 16:15:27 +00:00
package mocks
import (
2024-05-24 05:11:51 +00:00
"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
2024-05-26 07:15:50 +00:00
"github.com/docker/docker/api/types/image"
2024-05-24 05:11:51 +00:00
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"io"
2024-03-20 16:15:27 +00:00
)
2024-03-20 19:23:31 +00:00
type MockContainerClient struct {
2024-05-24 05:11:51 +00:00
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)
2024-07-17 08:34:57 +00:00
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)
2024-05-24 05:11:51 +00:00
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)
2024-07-17 08:34:57 +00:00
InjectImagePull func(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
2024-05-24 05:11:51 +00:00
InjectImageInspectWithRaw func(ctx context.Context, imageID string) (types.ImageInspect, []byte, error)
2024-07-17 08:34:57 +00:00
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)
2024-05-24 05:11:51 +00:00
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)
}
2024-07-17 08:34:57 +00:00
func (m *MockContainerClient) ImageRemove(ctx context.Context, imageID string, options image.RemoveOptions) ([]image.DeleteResponse, error) {
2024-05-24 05:11:51 +00:00
return m.InjectImageRemove(ctx, imageID, options)
}
2024-07-17 08:34:57 +00:00
func (m *MockContainerClient) ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error) {
2024-05-24 05:11:51 +00:00
return m.InjectImagePull(ctx, refStr, options)
}
func (m *MockContainerClient) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
return m.InjectImageBuild(ctx, buildContext, options)
}
2024-05-24 05:11:51 +00:00
func (m *MockContainerClient) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) {
return m.InjectImageInspectWithRaw(ctx, imageID)
2024-03-20 19:23:31 +00:00
}
func (m *MockContainerClient) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error) {
2024-05-24 05:11:51 +00:00
return m.InjectContainerCreate(ctx, config, hostConfig, networkingConfig, platform, containerName)
2024-03-20 19:23:31 +00:00
}
2024-03-22 04:35:17 +00:00
func (m *MockContainerClient) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error {
2024-05-24 05:11:51 +00:00
if m.InjectContainerStart == nil {
return nil
}
return m.InjectContainerStart(ctx, containerID, options)
2024-03-21 22:28:29 +00:00
}
2024-04-03 21:23:57 +00:00
func (m *MockContainerClient) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
2024-05-24 05:11:51 +00:00
return m.InjectContainerList(ctx, options)
2024-03-20 16:15:27 +00:00
}
2024-03-20 19:23:31 +00:00
func (m *MockContainerClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) {
2024-05-24 05:11:51 +00:00
return m.InjectContainerInspect(ctx, containerID)
2024-03-20 19:23:31 +00:00
}
func (m *MockContainerClient) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error {
2024-05-24 05:11:51 +00:00
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)
2024-03-20 19:23:31 +00:00
}
func (m *MockContainerClient) Close() error {
2024-05-24 05:11:51 +00:00
if m.InjectClose == nil {
return nil
}
return m.InjectClose()
2024-03-20 19:23:31 +00:00
}
2024-05-06 00:48:54 +00:00
2024-07-17 08:34:57 +00:00
func (m *MockContainerClient) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) {
2024-05-06 00:48:54 +00:00
return m.InjectNetworkCreate(ctx, name, options)
}
2024-07-17 08:34:57 +00:00
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)
}