jx/tests/mocks/container.go

50 lines
2.2 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-03-20 16:15:27 +00:00
package mocks
import (
2024-03-20 19:23:31 +00:00
"context"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/docker/docker/api/types"
2024-03-20 16:15:27 +00:00
)
2024-03-20 19:23:31 +00:00
type MockContainerClient struct {
2024-03-22 04:35:17 +00:00
InjectContainerStart func(ctx context.Context, containerID string, options container.StartOptions) error
2024-03-20 19:23:31 +00:00
InjectContainerCreate func(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
2024-04-03 21:23:57 +00:00
InjectContainerList func(context.Context, container.ListOptions) ([]types.Container, error)
2024-03-20 19:23:31 +00:00
InjectContainerInspect func(context.Context, string) (types.ContainerJSON, error)
InjectContainerRemove func(context.Context, string, container.RemoveOptions) error
InjectClose func() error
}
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)
}
2024-03-22 04:35:17 +00:00
func (m *MockContainerClient) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error {
2024-03-21 22:28:29 +00:00
if m.InjectContainerStart == nil {
return nil
}
return m.InjectContainerStart(ctx, containerID, options)
}
2024-04-03 21:23:57 +00:00
func (m *MockContainerClient) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
2024-03-20 19:23:31 +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) {
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) Close() error {
if m.InjectClose == nil {
return nil
}
return m.InjectClose()
}