mock

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mock provides mock implementations of the ports interfaces for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerService

type ContainerService struct {

	// Callbacks for customizing behavior
	OnCreate  func(ctx context.Context, config *domain.ContainerConfig) (string, error)
	OnStart   func(ctx context.Context, containerID string) error
	OnStop    func(ctx context.Context, containerID string, opts domain.StopOptions) error
	OnRemove  func(ctx context.Context, containerID string, opts domain.RemoveOptions) error
	OnInspect func(ctx context.Context, containerID string) (*domain.Container, error)
	OnList    func(ctx context.Context, opts domain.ListOptions) ([]domain.Container, error)
	OnWait    func(ctx context.Context, containerID string) (<-chan domain.WaitResponse, <-chan error)
	OnLogs    func(ctx context.Context, containerID string, opts domain.LogOptions) (io.ReadCloser, error)
	OnKill    func(ctx context.Context, containerID string, signal string) error

	// Call tracking
	CreateCalls  []CreateContainerCall
	StartCalls   []string
	StopCalls    []StopContainerCall
	RemoveCalls  []RemoveContainerCall
	InspectCalls []string
	ListCalls    []domain.ListOptions
	WaitCalls    []string
	LogsCalls    []LogsCall
	KillCalls    []KillCall
	// contains filtered or unexported fields
}

ContainerService is a mock implementation of ports.ContainerService.

func NewContainerService

func NewContainerService() *ContainerService

NewContainerService creates a new mock ContainerService.

func (*ContainerService) Attach

func (s *ContainerService) Attach(ctx context.Context, containerID string, opts ports.AttachOptions) (*domain.HijackedResponse, error)

Attach attaches to a container.

func (*ContainerService) CopyLogs

func (s *ContainerService) CopyLogs(ctx context.Context, containerID string, stdout, stderr io.Writer, opts domain.LogOptions) error

CopyLogs copies container logs to writers.

func (*ContainerService) Create

func (s *ContainerService) Create(ctx context.Context, config *domain.ContainerConfig) (string, error)

Create creates a container.

func (*ContainerService) Inspect

func (s *ContainerService) Inspect(ctx context.Context, containerID string) (*domain.Container, error)

Inspect returns container information.

func (*ContainerService) Kill

func (s *ContainerService) Kill(ctx context.Context, containerID string, signal string) error

Kill sends a signal to a container.

func (*ContainerService) List

List lists containers.

func (*ContainerService) Logs

func (s *ContainerService) Logs(ctx context.Context, containerID string, opts domain.LogOptions) (io.ReadCloser, error)

Logs returns container logs.

func (*ContainerService) Pause

func (s *ContainerService) Pause(ctx context.Context, containerID string) error

Pause pauses a container.

func (*ContainerService) Remove

func (s *ContainerService) Remove(ctx context.Context, containerID string, opts domain.RemoveOptions) error

Remove removes a container.

func (*ContainerService) Rename

func (s *ContainerService) Rename(ctx context.Context, containerID string, newName string) error

Rename renames a container.

func (*ContainerService) Start

func (s *ContainerService) Start(ctx context.Context, containerID string) error

Start starts a container.

func (*ContainerService) Stop

func (s *ContainerService) Stop(ctx context.Context, containerID string, opts domain.StopOptions) error

Stop stops a container.

func (*ContainerService) Unpause

func (s *ContainerService) Unpause(ctx context.Context, containerID string) error

Unpause unpauses a container.

func (*ContainerService) Wait

func (s *ContainerService) Wait(ctx context.Context, containerID string) (<-chan domain.WaitResponse, <-chan error)

Wait waits for a container to stop.

type CreateContainerCall

type CreateContainerCall struct {
	Config *domain.ContainerConfig
}

CreateContainerCall represents a call to Create().

type DockerClient

type DockerClient struct {
	// contains filtered or unexported fields
}

DockerClient is a mock implementation of ports.DockerClient.

func NewDockerClient

func NewDockerClient() *DockerClient

NewDockerClient creates a new mock DockerClient.

func (*DockerClient) Close

func (c *DockerClient) Close() error

Close closes the client.

func (*DockerClient) Containers

func (c *DockerClient) Containers() ports.ContainerService

Containers returns the container service.

func (*DockerClient) Events

func (c *DockerClient) Events() ports.EventService

Events returns the event service.

func (*DockerClient) Exec

func (c *DockerClient) Exec() ports.ExecService

Exec returns the exec service.

func (*DockerClient) Images

func (c *DockerClient) Images() ports.ImageService

Images returns the image service.

func (*DockerClient) IsClosed

func (c *DockerClient) IsClosed() bool

IsClosed returns true if the client has been closed.

func (*DockerClient) Networks

func (c *DockerClient) Networks() ports.NetworkService

Networks returns the network service.

func (*DockerClient) Services

func (c *DockerClient) Services() ports.SwarmService

Services returns the Swarm service.

func (*DockerClient) SetCloseError

func (c *DockerClient) SetCloseError(err error)

SetCloseError sets the error returned by Close().

func (*DockerClient) System

func (c *DockerClient) System() ports.SystemService

System returns the system service.

type EventService

type EventService struct {

	// Callbacks for customizing behavior
	OnSubscribe func(ctx context.Context, filter domain.EventFilter) (<-chan domain.Event, <-chan error)

	// Call tracking
	SubscribeCalls []domain.EventFilter
	// contains filtered or unexported fields
}

EventService is a mock implementation of ports.EventService.

func NewEventService

func NewEventService() *EventService

NewEventService creates a new mock EventService.

func (*EventService) AddContainerStopEvent

func (s *EventService) AddContainerStopEvent(containerID string)

AddContainerStopEvent adds a container stop event.

func (*EventService) AddEvent

func (s *EventService) AddEvent(event domain.Event)

AddEvent adds an event to send.

func (*EventService) ClearEvents

func (s *EventService) ClearEvents()

ClearEvents clears all simulated events.

func (*EventService) SetEvents

func (s *EventService) SetEvents(events []domain.Event)

SetEvents sets the events to send on Subscribe().

func (*EventService) SetSubscribeError

func (s *EventService) SetSubscribeError(err error)

SetSubscribeError sets an error to return during subscription.

func (*EventService) Subscribe

func (s *EventService) Subscribe(ctx context.Context, filter domain.EventFilter) (<-chan domain.Event, <-chan error)

Subscribe subscribes to Docker events.

func (*EventService) SubscribeWithCallback

func (s *EventService) SubscribeWithCallback(ctx context.Context, filter domain.EventFilter, callback ports.EventCallback) error

SubscribeWithCallback subscribes to events with a callback.

A pending error is reported even when the event channel has already been closed. Subscribe's goroutine buffers a configured subscribe error and then closes both channels, so once it has run to completion the error and the closed event channel are ready in the same instant — and a select picks between ready cases at random, which made the error reported or silently swallowed on a coin flip. Measured at 89 losses in 200 runs once the goroutine got there first, which is what a loaded CI runner arranges (#820).

type ExecCreateCall

type ExecCreateCall struct {
	ContainerID string
	Config      *domain.ExecConfig
}

ExecCreateCall represents a call to Create().

type ExecRunCall

type ExecRunCall struct {
	ContainerID string
	Config      *domain.ExecConfig
}

ExecRunCall represents a call to Run().

type ExecService

type ExecService struct {

	// Callbacks for customizing behavior
	OnCreate  func(ctx context.Context, containerID string, config *domain.ExecConfig) (string, error)
	OnStart   func(ctx context.Context, execID string, opts domain.ExecStartOptions) (*domain.HijackedResponse, error)
	OnInspect func(ctx context.Context, execID string) (*domain.ExecInspect, error)
	OnRun     func(ctx context.Context, containerID string, config *domain.ExecConfig, stdout, stderr io.Writer) (int, error)

	// Call tracking
	CreateCalls  []ExecCreateCall
	StartCalls   []ExecStartCall
	InspectCalls []string
	RunCalls     []ExecRunCall

	// Simulated output
	Output string
	// contains filtered or unexported fields
}

ExecService is a mock implementation of ports.ExecService.

func NewExecService

func NewExecService() *ExecService

NewExecService creates a new mock ExecService.

func (*ExecService) Create

func (s *ExecService) Create(ctx context.Context, containerID string, config *domain.ExecConfig) (string, error)

Create creates an exec instance.

func (*ExecService) Inspect

func (s *ExecService) Inspect(ctx context.Context, execID string) (*domain.ExecInspect, error)

Inspect returns exec information.

func (*ExecService) Run

func (s *ExecService) Run(ctx context.Context, containerID string, config *domain.ExecConfig, stdout, stderr io.Writer) (int, error)

Run runs a command in a container.

func (*ExecService) SetOutput

func (s *ExecService) SetOutput(output string)

SetOutput sets the simulated output for exec operations.

func (*ExecService) Start

Start starts an exec instance.

type ExecStartCall

type ExecStartCall struct {
	ExecID  string
	Options domain.ExecStartOptions
}

ExecStartCall represents a call to Start().

type ImageRemoveCall

type ImageRemoveCall struct {
	ImageID       string
	Force         bool
	PruneChildren bool
}

ImageRemoveCall represents a call to Remove().

type ImageService

type ImageService struct {

	// Callbacks for customizing behavior
	OnPull        func(ctx context.Context, opts domain.PullOptions) (io.ReadCloser, error)
	OnPullAndWait func(ctx context.Context, opts domain.PullOptions) error
	OnList        func(ctx context.Context, opts domain.ImageListOptions) ([]domain.ImageSummary, error)
	OnInspect     func(ctx context.Context, imageID string) (*domain.Image, error)
	OnRemove      func(ctx context.Context, imageID string, force, pruneChildren bool) error
	OnExists      func(ctx context.Context, imageRef string) (bool, error)

	// Call tracking
	PullCalls        []domain.PullOptions
	PullAndWaitCalls []domain.PullOptions
	ListCalls        []domain.ImageListOptions
	InspectCalls     []string
	RemoveCalls      []ImageRemoveCall
	ExistsCalls      []string

	// Simulated data
	Images       []domain.ImageSummary
	ExistsResult bool
	// contains filtered or unexported fields
}

ImageService is a mock implementation of ports.ImageService.

func NewImageService

func NewImageService() *ImageService

NewImageService creates a new mock ImageService.

func (*ImageService) Exists

func (s *ImageService) Exists(ctx context.Context, imageRef string) (bool, error)

Exists checks if an image exists.

func (*ImageService) Inspect

func (s *ImageService) Inspect(ctx context.Context, imageID string) (*domain.Image, error)

Inspect returns image information.

func (*ImageService) List

List lists images.

func (*ImageService) Pull

Pull pulls an image.

func (*ImageService) PullAndWait

func (s *ImageService) PullAndWait(ctx context.Context, opts domain.PullOptions) error

PullAndWait pulls an image and waits for completion.

func (*ImageService) Remove

func (s *ImageService) Remove(ctx context.Context, imageID string, force, pruneChildren bool) error

Remove removes an image.

func (*ImageService) SetExistsResult

func (s *ImageService) SetExistsResult(exists bool)

SetExistsResult sets the result returned by Exists().

func (*ImageService) SetImages

func (s *ImageService) SetImages(images []domain.ImageSummary)

SetImages sets the images returned by List().

func (*ImageService) Tag

func (s *ImageService) Tag(ctx context.Context, source, target string) error

Tag tags an image.

type KillCall

type KillCall struct {
	ContainerID string
	Signal      string
}

KillCall represents a call to Kill().

type LogsCall

type LogsCall struct {
	ContainerID string
	Options     domain.LogOptions
}

LogsCall represents a call to Logs().

type NetworkConnectCall

type NetworkConnectCall struct {
	NetworkID   string
	ContainerID string
	Config      *domain.EndpointSettings
}

NetworkConnectCall represents a call to Connect().

type NetworkCreateCall

type NetworkCreateCall struct {
	Name    string
	Options ports.NetworkCreateOptions
}

NetworkCreateCall represents a call to Create().

type NetworkDisconnectCall

type NetworkDisconnectCall struct {
	NetworkID   string
	ContainerID string
	Force       bool
}

NetworkDisconnectCall represents a call to Disconnect().

type NetworkService

type NetworkService struct {

	// Callbacks for customizing behavior
	OnConnect    func(ctx context.Context, networkID, containerID string, config *domain.EndpointSettings) error
	OnDisconnect func(ctx context.Context, networkID, containerID string, force bool) error
	OnList       func(ctx context.Context, opts domain.NetworkListOptions) ([]domain.Network, error)
	OnInspect    func(ctx context.Context, networkID string) (*domain.Network, error)
	OnCreate     func(ctx context.Context, name string, opts ports.NetworkCreateOptions) (string, error)
	OnRemove     func(ctx context.Context, networkID string) error

	// Call tracking
	ConnectCalls    []NetworkConnectCall
	DisconnectCalls []NetworkDisconnectCall
	ListCalls       []domain.NetworkListOptions
	InspectCalls    []string
	CreateCalls     []NetworkCreateCall
	RemoveCalls     []string

	// Simulated data
	Networks []domain.Network
	// contains filtered or unexported fields
}

NetworkService is a mock implementation of ports.NetworkService.

func NewNetworkService

func NewNetworkService() *NetworkService

NewNetworkService creates a new mock NetworkService.

func (*NetworkService) Connect

func (s *NetworkService) Connect(ctx context.Context, networkID, containerID string, config *domain.EndpointSettings) error

Connect connects a container to a network.

func (*NetworkService) Create

Create creates a network.

func (*NetworkService) Disconnect

func (s *NetworkService) Disconnect(ctx context.Context, networkID, containerID string, force bool) error

Disconnect disconnects a container from a network.

func (*NetworkService) Inspect

func (s *NetworkService) Inspect(ctx context.Context, networkID string) (*domain.Network, error)

Inspect returns network information.

func (*NetworkService) List

List lists networks.

func (*NetworkService) Remove

func (s *NetworkService) Remove(ctx context.Context, networkID string) error

Remove removes a network.

func (*NetworkService) SetNetworks

func (s *NetworkService) SetNetworks(networks []domain.Network)

SetNetworks sets the networks returned by List() and Inspect().

type RemoveContainerCall

type RemoveContainerCall struct {
	ContainerID string
	Options     domain.RemoveOptions
}

RemoveContainerCall represents a call to Remove().

type ServiceCreateCall

type ServiceCreateCall struct {
	Spec    domain.ServiceSpec
	Options domain.ServiceCreateOptions
}

ServiceCreateCall represents a call to Create().

type StopContainerCall

type StopContainerCall struct {
	ContainerID string
	Options     domain.StopOptions
}

StopContainerCall represents a call to Stop().

type SwarmService

type SwarmService struct {

	// Callbacks for customizing behavior
	OnCreate    func(ctx context.Context, spec domain.ServiceSpec, opts domain.ServiceCreateOptions) (string, error)
	OnInspect   func(ctx context.Context, serviceID string) (*domain.Service, error)
	OnList      func(ctx context.Context, opts domain.ServiceListOptions) ([]domain.Service, error)
	OnRemove    func(ctx context.Context, serviceID string) error
	OnListTasks func(ctx context.Context, opts domain.TaskListOptions) ([]domain.Task, error)

	// Call tracking
	CreateCalls    []ServiceCreateCall
	InspectCalls   []string
	ListCalls      []domain.ServiceListOptions
	RemoveCalls    []string
	ListTasksCalls []domain.TaskListOptions

	// Simulated data
	Services []domain.Service
	Tasks    []domain.Task
	// contains filtered or unexported fields
}

SwarmService is a mock implementation of ports.SwarmService.

func NewSwarmService

func NewSwarmService() *SwarmService

NewSwarmService creates a new mock SwarmService.

func (*SwarmService) AddCompletedTask

func (s *SwarmService) AddCompletedTask(serviceID, containerID string, exitCode int)

AddCompletedTask adds a completed task for a service.

func (*SwarmService) Create

Create creates a service.

func (*SwarmService) Inspect

func (s *SwarmService) Inspect(ctx context.Context, serviceID string) (*domain.Service, error)

Inspect returns service information.

func (*SwarmService) List

List lists services.

func (*SwarmService) ListTasks

func (s *SwarmService) ListTasks(ctx context.Context, opts domain.TaskListOptions) ([]domain.Task, error)

ListTasks lists tasks.

func (*SwarmService) Remove

func (s *SwarmService) Remove(ctx context.Context, serviceID string) error

Remove removes a service.

func (*SwarmService) SetServices

func (s *SwarmService) SetServices(services []domain.Service)

SetServices sets the services returned by List() and Inspect().

func (*SwarmService) SetTasks

func (s *SwarmService) SetTasks(tasks []domain.Task)

SetTasks sets the tasks returned by ListTasks().

func (*SwarmService) WaitForServiceTasks

func (s *SwarmService) WaitForServiceTasks(ctx context.Context, serviceID string, timeout time.Duration) ([]domain.Task, error)

WaitForServiceTasks waits for all service tasks to complete.

func (*SwarmService) WaitForTask

func (s *SwarmService) WaitForTask(ctx context.Context, taskID string, timeout time.Duration) (*domain.Task, error)

WaitForTask waits for a task to reach a terminal state.

type SystemService

type SystemService struct {

	// Callbacks for customizing behavior
	OnInfo      func(ctx context.Context) (*domain.SystemInfo, error)
	OnPing      func(ctx context.Context) (*domain.PingResponse, error)
	OnVersion   func(ctx context.Context) (*domain.Version, error)
	OnDiskUsage func(ctx context.Context) (*domain.DiskUsage, error)

	// Call tracking
	InfoCalls      int
	PingCalls      int
	VersionCalls   int
	DiskUsageCalls int

	// Simulated data
	InfoResult      *domain.SystemInfo
	PingResult      *domain.PingResponse
	VersionResult   *domain.Version
	DiskUsageResult *domain.DiskUsage

	// Errors
	InfoErr      error
	PingErr      error
	VersionErr   error
	DiskUsageErr error
	// contains filtered or unexported fields
}

SystemService is a mock implementation of ports.SystemService.

func NewSystemService

func NewSystemService() *SystemService

NewSystemService creates a new mock SystemService.

func (*SystemService) DiskUsage

func (s *SystemService) DiskUsage(ctx context.Context) (*domain.DiskUsage, error)

DiskUsage returns disk usage information.

func (*SystemService) Info

Info returns system information.

func (*SystemService) Ping

Ping pings the Docker server.

func (*SystemService) SetDiskUsageError

func (s *SystemService) SetDiskUsageError(err error)

SetDiskUsageError sets the error returned by DiskUsage().

func (*SystemService) SetDiskUsageResult

func (s *SystemService) SetDiskUsageResult(usage *domain.DiskUsage)

SetDiskUsageResult sets the result returned by DiskUsage().

func (*SystemService) SetInfoError

func (s *SystemService) SetInfoError(err error)

SetInfoError sets the error returned by Info().

func (*SystemService) SetInfoResult

func (s *SystemService) SetInfoResult(info *domain.SystemInfo)

SetInfoResult sets the result returned by Info().

func (*SystemService) SetPingError

func (s *SystemService) SetPingError(err error)

SetPingError sets the error returned by Ping().

func (*SystemService) SetPingResult

func (s *SystemService) SetPingResult(ping *domain.PingResponse)

SetPingResult sets the result returned by Ping().

func (*SystemService) SetVersionError

func (s *SystemService) SetVersionError(err error)

SetVersionError sets the error returned by Version().

func (*SystemService) SetVersionResult

func (s *SystemService) SetVersionResult(version *domain.Version)

SetVersionResult sets the result returned by Version().

func (*SystemService) Version

func (s *SystemService) Version(ctx context.Context) (*domain.Version, error)

Version returns version information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL