harness

package
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package harness holds the fakes the end-to-end tests drive the real app against: a stateful Docker Engine API, canned earning providers and a canned exchange-rate feed.

Everything here listens on 127.0.0.1 over TCP, never a unix socket and never a named pipe, so the same tests run unchanged on linux, macOS and windows with no container runtime installed, no provider accounts and no internet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	ID     string
	Name   string
	Image  string
	State  string
	Labels map[string]string
	Env    []string
	Cmd    []string
	// Entrypoint and StopTimeout are what the deploy asked Docker for; nil means
	// it asked for neither (the image's entrypoint, the daemon's 10 seconds).
	Entrypoint  []string
	StopTimeout *int
	Mounts      []Mount
}

Container is one container the fake daemon is holding, as the tests want to read it: the state a user would see plus the pieces a deploy is supposed to carry across (image, labels, environment, command, named volumes).

func (Container) VolumeNames

func (c Container) VolumeNames() []string

VolumeNames lists the names of the container's named volumes, in the order the deploy asked for them.

type Docker

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

Docker is a fake Docker Engine API with state. It answers the endpoints the app actually calls, keeps containers, images and volumes between calls, and records every request so a test can assert on the ORDER of what happened — which is the part a return value cannot show (a deploy that fails and a deploy that fails after destroying the running container both just return an error).

func NewDocker

func NewDocker() *Docker

NewDocker starts the fake daemon on a loopback TCP port.

func (*Docker) Calls

func (d *Docker) Calls() []string

Calls returns the requests seen so far as "METHOD /path", in order.

func (*Docker) CallsWithQuery

func (d *Docker) CallsWithQuery() []string

CallsWithQuery is Calls with the query string kept, as "METHOD /path?query". The query is where the Engine API carries the options that change what a call destroys — removing a container with v=1 takes its anonymous volumes with it, v=0 leaves them — so a test about what survived needs to see it.

func (*Docker) Close

func (d *Docker) Close()

Close shuts the fake down.

func (*Docker) Container

func (d *Docker) Container(nameOrID string) (Container, bool)

Container returns the container with this name (or id).

func (*Docker) Host

func (d *Docker) Host() string

Host is the value to put in DOCKER_HOST so the app's own client finds this fake with no seam added to production code.

func (*Docker) Images

func (d *Docker) Images() []string

Images returns every image reference that was pulled, in order.

func (*Docker) Names

func (d *Docker) Names() []string

Names returns every container the fake holds, sorted.

func (*Docker) ResetCalls

func (d *Docker) ResetCalls()

ResetCalls clears the recorded calls so a test can assert on one phase alone.

func (*Docker) SetDown

func (d *Docker) SetDown(down bool)

SetDown makes the daemon go away (every request has its connection dropped, the way a stopped daemon refuses one) or come back.

func (*Docker) SetDownAfter

func (d *Docker) SetDownAfter(call string)

SetDownAfter makes the daemon go away as soon as it has answered this call ("METHOD /path"), so a test can cut it off in the middle of an operation at a chosen point rather than hoping to hit the right moment.

func (*Docker) SetLogs

func (d *Docker) SetLogs(text string)

SetLogs replaces the log text the fake streams back.

func (*Docker) SetPullError

func (d *Docker) SetPullError(message string)

SetPullError makes the next image pull fail mid-stream with this message, the way a registry outage or a mistyped image does.

func (*Docker) Volumes

func (d *Docker) Volumes() []string

Volumes returns every named volume the fake holds, sorted.

type Mount

type Mount struct {
	Source string
	Target string
}

Mount is one named volume attached to a container: the volume's name on the host and the path it appears at inside the container. Both halves are kept because both matter — the name is what an explicit volume delete addresses, and the path is how you tell an earner's identity data apart from a scratch directory, which is the difference between a safe delete and a device that has to be registered again.

type Providers

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

Providers is a stand-in for the earning platforms and the exchange-rate feeds. One loopback server answers for every hostname the collectors call, so a test can drive the real collectors — real request building, real auth round-trip, real JSON decode, real HTTP over TCP — with no accounts and no internet.

Requests reach it because Client() hands back an http.Client whose transport sends every request to this server while leaving the Host header alone; the handler routes on that Host, the way a real host would.

func NewProviders

func NewProviders() *Providers

NewProviders starts the fake platform and rate server on a loopback TCP port with a usable set of balances and rates already in place.

func (*Providers) Client

func (p *Providers) Client() *http.Client

Client is the http.Client to hand the collectors: it keeps their real, hardcoded URLs and simply delivers the requests here.

func (*Providers) Close

func (p *Providers) Close()

Close shuts the fake down.

func (*Providers) Hits

func (p *Providers) Hits(platform string) int

Hits reports how many requests a platform has had, so a test can prove a collector really went out to the network rather than reading a cache.

func (*Providers) SetBalance

func (p *Providers) SetBalance(platform string, amount float64)

SetBalance changes what a platform reports next time it is asked.

func (*Providers) SetCryptoUSD

func (p *Providers) SetCryptoUSD(coingeckoID string, usd float64)

SetCryptoUSD sets the dollar price of a token, keyed by its CoinGecko id.

func (*Providers) SetFailing

func (p *Providers) SetFailing(platform string, failing bool)

SetFailing makes a platform answer HTTP 500, the way an outage does.

func (*Providers) SetFiat

func (p *Providers) SetFiat(code string, rate float64)

SetFiat sets a USD -> fiat rate.

func (*Providers) URL

func (p *Providers) URL() string

URL is the base URL of the fake, for the rate feeds which take one directly.

Jump to

Keyboard shortcuts

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