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 ¶
- type Container
- type Docker
- func (d *Docker) AttachNetwork(name, network string)
- func (d *Docker) BeforeCall(call string, hook func())
- func (d *Docker) Calls() []string
- func (d *Docker) CallsWithQuery() []string
- func (d *Docker) ClearFailures()
- func (d *Docker) Close()
- func (d *Docker) Container(nameOrID string) (Container, bool)
- func (d *Docker) FailAfterCreate(name, message string)
- func (d *Docker) FailCreate(name, message string)
- func (d *Docker) FailInspect(name string)
- func (d *Docker) FailInspectFrom(nameOrID string, n int)
- func (d *Docker) FailRemove(name string)
- func (d *Docker) FailRename(name string)
- func (d *Docker) FailStart(name string, fail bool)
- func (d *Docker) FailStartOfNext(name, message string)
- func (d *Docker) FailStop(name string)
- func (d *Docker) Host() string
- func (d *Docker) Images() []string
- func (d *Docker) Names() []string
- func (d *Docker) RemoveNetwork(name string)
- func (d *Docker) Rename(name, to string)
- func (d *Docker) ResetCalls()
- func (d *Docker) SetDown(down bool)
- func (d *Docker) SetDownAfter(call string)
- func (d *Docker) SetLabel(name, key, value string)
- func (d *Docker) SetLogs(text string)
- func (d *Docker) SetPullError(message string)
- func (d *Docker) SetRestartPolicy(name, policy string)
- func (d *Docker) SetState(name, state string)
- func (d *Docker) SetStateError(name, message string)
- func (d *Docker) Volumes() []string
- type Mount
- type PortBinding
- type Providers
- func (p *Providers) Client() *http.Client
- func (p *Providers) Close()
- func (p *Providers) Hits(platform string) int
- func (p *Providers) SetBalance(platform string, amount float64)
- func (p *Providers) SetCryptoUSD(coingeckoID string, usd float64)
- func (p *Providers) SetFailing(platform string, failing bool)
- func (p *Providers) SetFiat(code string, rate float64)
- func (p *Providers) URL() string
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
// Runtime, NetworkMode and PortBindings are the HostConfig fields of the same
// names, as the deploy sent them.
Runtime string
NetworkMode string
PortBindings map[string][]PortBinding
// RestartPolicy is the HostConfig restart policy's name, as the deploy sent it or
// a later container update set it.
RestartPolicy string
// ExtraNetworks are networks a test attached it to beside its network mode.
ExtraNetworks []string
// StateError is inspect's State.Error: why Docker's last start of it failed.
// A start that works clears it.
StateError string
// contains filtered or unexported fields
}
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 ¶
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 (*Docker) AttachNetwork ¶ added in v1.0.5
AttachNetwork reports the container attached to one more network.
func (*Docker) BeforeCall ¶ added in v1.0.9
BeforeCall makes the next request seen as call ("METHOD /path") run hook before it is answered, outside the fake's lock, so the hook can call the fake. A container's path may name it by name or by id: "POST /containers/cashpilot-x/start" matches a start of that container under its id too. A test uses it to act at an exact point in the middle of an operation.
func (*Docker) CallsWithQuery ¶
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) ClearFailures ¶ added in v1.0.9
func (d *Docker) ClearFailures()
ClearFailures drops every inspect, stop, start, rename and remove failure set so far, the way a daemon that was struggling recovers.
func (*Docker) FailAfterCreate ¶ added in v1.0.9
FailAfterCreate makes the next create under this name make the container and still answer an error with message, as a create whose reply never arrived.
func (*Docker) FailCreate ¶ added in v1.0.9
FailCreate makes the next create of a container under this name fail with message, the way Docker refuses a create.
func (*Docker) FailInspect ¶ added in v1.0.5
FailInspect makes inspecting this container fail with a server error.
func (*Docker) FailInspectFrom ¶ added in v1.0.9
FailInspectFrom makes inspecting by exactly this name or id fail from the nth such inspect after this call on (n counts from 1). Unlike FailInspect it matches the request, not the container: an inspect of the same container under its other name or its id still works.
func (*Docker) FailRemove ¶ added in v1.0.9
FailRemove makes removing this container fail with a server error.
func (*Docker) FailRename ¶ added in v1.0.9
FailRename makes renaming this container fail with a server error. The name is the one the container has when the rename is asked for.
func (*Docker) FailStart ¶ added in v1.0.8
FailStart makes starting this container fail with a server error (fail true), or work again (fail false).
func (*Docker) FailStartOfNext ¶ added in v1.0.9
FailStartOfNext makes the next container created under this name fail every start with message, the way Docker refuses a container whose published port a host process holds. Containers that already exist are not affected.
func (*Docker) FailStop ¶ added in v1.0.5
FailStop makes stopping this container fail with a server error.
func (*Docker) Host ¶
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) RemoveNetwork ¶ added in v1.0.5
RemoveNetwork deletes a network behind the app's back, the way a user's `docker network rm` or a daemon reset would.
func (*Docker) Rename ¶ added in v1.0.9
Rename renames a container behind the app's back, the way a deploy that died midway leaves one under another name.
func (*Docker) ResetCalls ¶
func (d *Docker) ResetCalls()
ResetCalls clears the recorded calls so a test can assert on one phase alone.
func (*Docker) SetDown ¶
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 ¶
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) SetLabel ¶ added in v1.0.5
SetLabel sets (or, with value "", removes) one label of a container, the way a container made by an older version lacks a label a newer one sets.
func (*Docker) SetPullError ¶
SetPullError makes the next image pull fail mid-stream with this message, the way a registry outage or a mistyped image does.
func (*Docker) SetRestartPolicy ¶ added in v1.0.8
SetRestartPolicy sets a container's restart policy, the way a container made by an older version keeps the policy it was created with.
func (*Docker) SetState ¶ added in v1.0.5
SetState sets a container's state as Docker would report it ("restarting").
func (*Docker) SetStateError ¶ added in v1.0.8
SetStateError sets a container's State.Error, as Docker records a start that failed ("network ... not found").
type Mount ¶
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 PortBinding ¶ added in v1.0.5
PortBinding is one host binding of a published port.
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 ¶
Client is the http.Client to hand the collectors: it keeps their real, hardcoded URLs and simply delivers the requests here.
func (*Providers) Hits ¶
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 ¶
SetBalance changes what a platform reports next time it is asked.
func (*Providers) SetCryptoUSD ¶
SetCryptoUSD sets the dollar price of a token, keyed by its CoinGecko id.
func (*Providers) SetFailing ¶
SetFailing makes a platform answer HTTP 500, the way an outage does.