mocks

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateContainerForProgress

func CreateContainerForProgress(index int, idPrefix int, nameFormat string) (wt.Container, wt.ImageID)

CreateContainerForProgress creates a container substitute for tracking session/update progress

func CreateMockContainer

func CreateMockContainer(id string, name string, image string, created time.Time) wt.Container

CreateMockContainer creates a container substitute valid for testing

func CreateMockContainerWithConfig

func CreateMockContainerWithConfig(id string, name string, image string, running bool, restarting bool, created time.Time, config *dockerContainer.Config) wt.Container

CreateMockContainerWithConfig creates a container substitute valid for testing

func CreateMockContainerWithDigest

func CreateMockContainerWithDigest(id string, name string, image string, created time.Time, digest string) wt.Container

CreateMockContainerWithDigest should only be used for testing

func CreateMockContainerWithImageInfo

func CreateMockContainerWithImageInfo(id string, name string, image string, created time.Time, imageInfo dockerImage.InspectResponse) wt.Container

CreateMockContainerWithImageInfo should only be used for testing

func CreateMockContainerWithImageInfoP

func CreateMockContainerWithImageInfoP(id string, name string, image string, created time.Time, imageInfo *dockerImage.InspectResponse) wt.Container

CreateMockContainerWithImageInfoP should only be used for testing

func CreateMockContainerWithLinks(id string, name string, image string, created time.Time, links []string, imageInfo *dockerImage.InspectResponse) wt.Container

CreateMockContainerWithLinks should only be used for testing

func CreateMockImageInfo

func CreateMockImageInfo(image string) *dockerImage.InspectResponse

CreateMockImageInfo returns a mock image info struct based on the passed image

func CreateMockProgressReport

func CreateMockProgressReport(states ...session.State) wt.Report

CreateMockProgressReport creates a mock report from a given set of container states All containers will be given a unique ID and name based on its state and index

Types

type MockClient

type MockClient struct {
	TestData *TestData
	// contains filtered or unexported fields
}

MockClient is a mock that passes as a dockwatch Client

func CreateMockClient

func CreateMockClient(data *TestData, pullImages bool, removeVolumes bool) MockClient

CreateMockClient creates a mock dockwatch Client for usage in tests

func (MockClient) ExecuteCommand

func (client MockClient) ExecuteCommand(_ t.ContainerID, command string, _ int) (SkipUpdate bool, err error)

ExecuteCommand is a mock method

func (MockClient) GetContainer

func (client MockClient) GetContainer(_ t.ContainerID) (t.Container, error)

GetContainer is a mock method

func (MockClient) IsContainerStale

func (client MockClient) IsContainerStale(cont t.Container, params t.UpdateParams) (bool, t.ImageID, error)

IsContainerStale is true if not explicitly stated in TestData for the mock client. A container named in StalenessError fails its check instead, as it would when the registry is unreachable or the credentials have expired.

func (MockClient) ListContainers

func (client MockClient) ListContainers(_ t.Filter) ([]t.Container, error)

ListContainers is a mock method returning the provided container testdata

func (MockClient) Ping added in v0.2.1

func (client MockClient) Ping() error

Ping is a mock method that always succeeds

func (MockClient) RemoveImageByID

func (client MockClient) RemoveImageByID(_ t.ImageID) error

RemoveImageByID increments the TriedToRemoveImageCount on being called

func (MockClient) RenameContainer

func (client MockClient) RenameContainer(_ t.Container, _ string) error

RenameContainer is a mock method

func (MockClient) StartContainer

func (client MockClient) StartContainer(c t.Container) (t.ContainerID, error)

StartContainer is a mock method that records which containers were started

func (MockClient) StopContainer

func (client MockClient) StopContainer(c t.Container, _ time.Duration) error

StopContainer is a mock method

func (MockClient) WarnOnHeadPullFailed

func (client MockClient) WarnOnHeadPullFailed(_ t.Container) bool

WarnOnHeadPullFailed is always true for the mock client

type TestData

type TestData struct {
	TriedToRemoveImageCount int
	NameOfContainerToKeep   string
	Containers              []t.Container
	Staleness               map[string]bool
	// StalenessError maps a container name to the error its staleness check should
	// return, for exercising the paths where dockwatch cannot determine staleness.
	StalenessError map[string]error
	// StopErrors maps a container name to the error its stop should return, for
	// exercising how the update flow reacts to a specific stop failure.
	StopErrors map[string]error
	// StartedContainers records the name of every container StartContainer was
	// called for, so a test can assert that a container dockwatch failed to stop
	// was not started again.
	StartedContainers []string
}

TestData is the data used to perform the test

func (*TestData) TriedToRemoveImage

func (testdata *TestData) TriedToRemoveImage() bool

TriedToRemoveImage is a test helper function to check whether RemoveImageByID has been called

Jump to

Keyboard shortcuts

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