jx/tests/mocks/container.go
Matthew Rich 43a2274b7e
Some checks failed
Lint / golangci-lint (push) Failing after 9m50s
Declarative Tests / test (push) Failing after 10s
update container/iptables resources
2024-05-05 17:48:54 -07:00

55 lines
2.5 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package mocks
import (
"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"
)
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 types.NetworkCreate) (types.NetworkCreateResponse, 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
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)
}
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) Close() error {
if m.InjectClose == nil {
return nil
}
return m.InjectClose()
}
func (m *MockContainerClient) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
return m.InjectNetworkCreate(ctx, name, options)
}