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) Calls() []string
- func (d *Docker) CallsWithQuery() []string
- func (d *Docker) Close()
- func (d *Docker) Container(nameOrID string) (Container, bool)
- func (d *Docker) Host() string
- func (d *Docker) Images() []string
- func (d *Docker) Names() []string
- func (d *Docker) ResetCalls()
- func (d *Docker) SetDown(down bool)
- func (d *Docker) SetDownAfter(call string)
- func (d *Docker) SetLogs(text string)
- func (d *Docker) SetPullError(message string)
- func (d *Docker) Volumes() []string
- type Mount
- 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
}
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) 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) 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) 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) SetPullError ¶
SetPullError makes the next image pull fail mid-stream with this message, the way a registry outage or a mistyped image does.
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 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.