Documentation
¶
Overview ¶
Package testenv keeps test binaries away from the developer's environment.
Every test package runs its tests through Main:
func TestMain(m *testing.M) {
testenv.Main(m)
}
Main points the home directory, HOME and on Windows USERPROFILE, at a new empty directory, so tests never read or write the developer's ~/.ahasend, and routes every request to a non-loopback host to a closed local port, so no test can reach the AhaSend API. Requests to loopback hosts are never proxied, so httptest servers keep working. Main also fails every DNS lookup, so connections the proxy does not cover, such as the SMTP connection of smtp send, reach only IP addresses and the hosts in /etc/hosts. A TestMain that cleans up after the tests calls Run instead.
Index ¶
Constants ¶
const BlockedProxy = "http://127.0.0.1:1"
BlockedProxy is a local port nothing listens on. Every request to a non-loopback host goes through it and fails at once.
Variables ¶
var ErrDNSBlocked = errors.New("testenv: DNS lookups are blocked; tests may only connect to loopback servers")
ErrDNSBlocked is the error of every DNS lookup in a test binary.
Functions ¶
func Main ¶
Main runs the tests of a package in an isolated environment and exits with their result.
Types ¶
This section is empty.