Documentation
¶
Overview ¶
Package installtest runs the install scripts in public/ as a black box. It serves a fake CLI release over HTTP, runs a script with sh or pwsh against it, and exposes what a test can observe afterwards: the script's output and exit status, the requests the release received and the argv each stub CLI recorded.
Index ¶
Constants ¶
const ChecksumsName = "checksums.txt"
ChecksumsName is the name of the file in a release that lists the SHA-256 digest of each archive.
const DefaultTag = "v9.9.9"
DefaultTag is the version a fake release reports as latest when the test names none.
const ReleaseStubName = "release"
ReleaseStubName is the name of the stub in a fake release when the test gives no stub of its own.
Variables ¶
This section is empty.
Functions ¶
func InitArgs ¶
InitArgs is the argv of a serverless init call for the App directory dir. The "--" ends flag parsing, so that a directory such as --force stays a directory.
func Stub ¶
func Stub(cfg StubConfig) string
Stub returns the content of a stub runware binary shaped by cfg.
Types ¶
type GitHubShim ¶
type GitHubShim struct {
Dir string
// contains filtered or unexported fields
}
GitHubShim is a directory holding a curl that stands in for the real one. It sends the default GitHub release URLs to a fake release and logs every URL it was asked for. Put Dir first on PATH to run a script with no RUNWARE_RELEASE_BASE_URL and still stay offline.
type Invocation ¶
type Invocation struct {
// Script is the path of the script to run.
Script string
// Args are the script's positional arguments.
Args []string
// Env sets environment variables for the script. It can override HOME
// and TMPDIR, which otherwise point at fresh temporary directories.
Env map[string]string
// PathDirs come before the standard tool directories on PATH.
PathDirs []string
// Timeout bounds the run. Zero means 30 seconds.
Timeout time.Duration
}
Invocation describes one run of an install script.
type Release ¶
type Release struct {
URL string
// contains filtered or unexported fields
}
Release is a fake CLI release served over HTTP. Its URL is the value a script reads from RUNWARE_RELEASE_BASE_URL: the latest-version lookup is at URL/latest and the release files are at URL/download/<tag>/<file>.
func NewRelease ¶
func NewRelease(t testing.TB, cfg ReleaseConfig) *Release
NewRelease starts a fake release that stops when the test ends.
func (*Release) GitHubShim ¶
func (r *Release) GitHubShim(t testing.TB) GitHubShim
GitHubShim writes a curl shim that routes the GitHub release URLs to r. The test skips where there is no curl to run behind the shim.
type ReleaseArchive ¶
type ReleaseArchive struct {
// Name is the file name of the archive.
Name string
// Binary is the name of the runware binary at the root of the archive.
Binary string
}
ReleaseArchive is one archive in a release.
func ReleaseArchives ¶
func ReleaseArchives() []ReleaseArchive
ReleaseArchives returns every archive a fake release serves.
type ReleaseConfig ¶
type ReleaseConfig struct {
// Tag is the version the latest-version lookup reports.
Tag string
// Stub is the content of the runware binary in the archive, usually
// from Stub.
Stub string
// BadChecksum makes checksums.txt list, for every archive, a digest that
// does not match it, as a tampered download would.
BadChecksum bool
}
ReleaseConfig shapes a fake release. The zero value serves DefaultTag with correct checksums and a stub named ReleaseStubName that has init.
type Result ¶
type Result struct {
ExitCode int
// Output is stdout and stderr combined.
Output string
// contains filtered or unexported fields
}
Result is what a script run left behind.
func RunPwsh ¶
func RunPwsh(t testing.TB, inv Invocation) Result
RunPwsh runs a PowerShell install script with pwsh, in the same clean environment as RunSh. Such a script takes no arguments, so inv.Args must be empty. The test skips where pwsh is missing, and on Windows: there the stub CLI, a sh script, cannot run as runware.exe.
func RunSh ¶
func RunSh(t testing.TB, inv Invocation) Result
RunSh runs a POSIX install script with sh. The script sees only the environment the invocation gives it, so the developer's own RUNWARE_* variables and Homebrew never leak in. The test skips where sh is missing, where the script's PATH has no curl, and on Windows, which the POSIX scripts do not support.
type StubCall ¶
type StubCall struct {
// Stub is the StubConfig.Name of the stub that ran.
Stub string
Args []string
}
StubCall is one call to a stub CLI.
type StubConfig ¶
type StubConfig struct {
// Name labels the calls this stub records, so that a test with more than
// one stub can tell them apart.
Name string
// WithoutInit makes the stub act as a CLI from before serverless init.
// Then "serverless init --help" prints the help of the serverless group
// and exits 0, as Cobra does for an unknown subcommand.
WithoutInit bool
// InitExit is the exit status of a serverless init call that does not ask
// for help.
InitExit int
}
StubConfig shapes a stub runware binary. The zero value is a CLI that has serverless init and whose init succeeds.
type Tripwires ¶
type Tripwires struct {
Dir string
// contains filtered or unexported fields
}
Tripwires is a directory of tools that a script must never run. Each one logs its command line and exits 1. Put Dir first on PATH, and check Calls after the run.
func NewTripwires ¶
NewTripwires writes a tripwire for each of the named tools.