Documentation
¶
Overview ¶
Package env is what a suite against a live server in a container is handed: the variables its test script exports, the replay proxy the server's internet calls go through, a check the container can reach it, the report on what the proxy saw, and files laid out where the container reads them. Every variable carries the app's prefix: New("APP") reads APP_SERVER, APP_TOKEN and the rest.
Index ¶
- Constants
- func CopyTree(t *testing.T, root, src, dst string)
- func FilesUnder(t *testing.T, dirs ...string) map[string][]byte
- func Mkdir(t *testing.T, root, dir string)
- func SameTree(t *testing.T, root string, before, after map[string][]byte)
- func StillOnDisk(t *testing.T, root string, files map[string][]byte, after string)
- func TreeOf(t *testing.T, root string, skip ...string) map[string][]byte
- func WriteFile(t *testing.T, path string, data []byte)
- type Env
- func (e Env) CheckReachable(ctx context.Context, what string, port int) (network string, err error)
- func (e Env) Configured(also ...string) bool
- func (e Env) Container() string
- func (e Env) ContainerAddresses(ctx context.Context) []string
- func (e Env) DataDir(elem ...string) string
- func (e Env) Get(name string) string
- func (e Env) Host() string
- func (e Env) ListenProxy(ctx context.Context, opts replayproxy.Options) (*Proxy, error)
- func (e Env) Mode() replayproxy.Mode
- func (e Env) ProxyPort() (int, error)
- func (e Env) Recording() bool
- func (e Env) Server() string
- func (e Env) StartProxy(ctx context.Context, opts replayproxy.Options) (*Proxy, error)
- func (e Env) Token() string
- func (e Env) Var(name string) string
- func (e Env) Verifying() bool
- type Proxy
Constants ¶
const DefaultHost = "host.docker.internal"
DefaultHost is the name a container reaches the machine it runs on by when the environment names none.
const DefaultProxyPort = 18080
DefaultProxyPort is the port the proxy listens on when the environment names none.
Variables ¶
This section is empty.
Functions ¶
func CopyTree ¶
CopyTree copies a folder under the tree at root, and everything under it, to a new place.
func FilesUnder ¶
FilesUnder reads every file under the folders, to hold them to later (StillOnDisk); folders with nothing under them fail the test.
func Mkdir ¶
Mkdir makes a directory under root that the server's own user can write in. The umask narrows what MkdirAll gives, so on Linux the server could not delete what the test laid out; chmod is not filtered. Docker Desktop hides this, so it only bites in CI.
func SameTree ¶
SameTree fails for every path that changed, went or appeared between two reads of a tree (TreeOf), named without root.
func StillOnDisk ¶
StillOnDisk checks every file read by FilesUnder is where it was, as it was, after what the test did (after), naming a file without root.
Types ¶
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env reads one app's test environment.
func (Env) CheckReachable ¶ added in v0.6.0
CheckReachable proves from inside the container that it can reach what this machine serves on port, by Host, and says what it sees of the network. A server that cannot reach the proxy fails every lookup, which reads as dozens of unrelated failures, so this says it once, plainly.
func (Env) Configured ¶
Configured reports whether the container environment is present: a server and a token, and each of the other variables a suite cannot run without.
func (Env) Container ¶
Container is the name of the container the test script started (APP_TEST_CONTAINER), "" when the server under test is not one of ours.
func (Env) ContainerAddresses ¶
ContainerAddresses are the addresses the server reaches itself on, which go through the proxy because NO_PROXY is set before docker hands them out; nil with no container, or when docker cannot say.
func (Env) DataDir ¶
DataDir is the host folder the container's data is mounted from (APP_TEST_DATA) with elem joined on, so a test can lay files out for the server. "" when unset, which a test must skip on or it writes into the checkout.
func (Env) Host ¶ added in v0.6.0
Host is the name the container reaches this machine by (APP_TEST_HOST), DefaultHost when unset; on Linux a script may give the bridge gateway's address instead.
func (Env) ListenProxy ¶ added in v0.6.0
ListenProxy brings the proxy up without asking the container anything, for a server that calls out as it starts. The environment sets the mode, the address (every interface on ProxyPort), the authority under APP_TEST_PROXY_CA, and the server's own addresses to ignore; the rest is the suite's. With no CassetteDir the suite keeps no recordings and a miss is told so rather than told to record.
func (Env) Mode ¶
func (e Env) Mode() replayproxy.Mode
Mode is how the environment asks the proxy to run: replaying unless told to record or to verify, and recording when told both.
func (Env) ProxyPort ¶
ProxyPort is the port the proxy listens on, APP_TEST_PROXY_PORT or DefaultProxyPort, which the container's HTTPS_PROXY already names.
func (Env) Recording ¶
Recording reports whether this run may call the real services: APP_TEST_RECORD=1 records only what is missing, =all records everything afresh.
func (Env) StartProxy ¶
StartProxy brings up the proxy the container's HTTPS_PROXY points at (ListenProxy) and proves the container can reach it. The container must be running; a suite that starts it after the proxy calls ListenProxy, starts it, then CheckReachable.
type Proxy ¶
type Proxy struct {
// Misses are the requests with no recording, Drifts the answers that changed shape since recording; both read when the proxy stops
Misses []string
Drifts []replayproxy.Drift
// contains filtered or unexported fields
}
Proxy is the replay proxy a suite runs for its whole run, and what it saw once stopped.
func (*Proxy) Report ¶
Report says what a stopped proxy saw that fails a run, "" for nothing: a miss, which means a test ran against a 502, with what to do about it; and a drift, a service answering in a new shape.
func (*Proxy) Serve ¶
Serve answers a host, or one path of it, with h rather than a recording until stop is called (replayproxy.Proxy.Serve).