Documentation ¶
Overview ¶
Package runner provides helpers for compiling and running the Terramate binary with the intent of doing e2e tests. Additionally, it also provides functions for building and installing dependency binaries.
Index ¶
- Variables
- func AssertRun(t *testing.T, got RunResult)
- func AssertRunResult(t *testing.T, got RunResult, want RunExpected)
- func BuildTerramate(projectRoot, binDir string) (string, error)
- func BuildTestHelper(projectRoot, binDir string) (string, error)
- func InstallTerraform(preferredVersion string) (string, string, func(), error)
- func PollBufferForMsgs(buf *buffer, done chan error, wantMsgs ...string) error
- func RemoveEnv(environ []string, names ...string) []string
- func SendUntilMsgIsReceived(t *testing.T, cmd *Cmd, signal os.Signal, msgs ...string)
- func Setup(projectRoot string) (err error)
- func Teardown()
- type CLI
- func (tm CLI) ListChangedStacks(args ...string) RunResult
- func (tm CLI) ListStacks(args ...string) RunResult
- func (tm CLI) NewCmd(args ...string) *Cmd
- func (tm *CLI) NewRunFixture(mode RunMode, rootdir string, flags ...string) RunFixture
- func (tm *CLI) PrependToPath(dir string)
- func (tm CLI) Run(args ...string) RunResult
- func (tm CLI) RunScript(args ...string) RunResult
- func (tm CLI) RunWithStdin(stdin string, args ...string) RunResult
- func (tm CLI) StacksRunGraph(args ...string) RunResult
- func (tm CLI) StacksRunOrder(args ...string) RunResult
- func (tm CLI) TriggerStack(stack string) RunResult
- type Cmd
- type RunExpected
- type RunFixture
- type RunMode
- type RunResult
Constants ¶
This section is empty.
Variables ¶
var HelperPath string
HelperPath is the path to the test binary we compiled for test purposes
var HelperPathAsHCL string
HelperPathAsHCL is the path to the test binary but as a safe HCL expression that's valid in all supported OSs.
var TerraformTestPath string
TerraformTestPath is the path to the installed terraform binary.
var TerraformVersion string
TerraformVersion is the detected or installed Terraform version.
Functions ¶
func AssertRunResult ¶
func AssertRunResult(t *testing.T, got RunResult, want RunExpected)
AssertRunResult asserts that the result matches the expected.
func BuildTerramate ¶
BuildTerramate build the Terramate binary from the current filesystem tree provided in the projectRoot directory. The binary is built into the provided binDir directory. The projectRoot is also used to compute the Terramate main package.
func BuildTestHelper ¶
BuildTestHelper builds the helper tool from the provided projectRoot directory into the binDir directory. The projectRoot is also used to compute the helper main package.
func InstallTerraform ¶
InstallTerraform installs Terraform (if needed). The preferredVersion is used if terraform is not yet installed.
func PollBufferForMsgs ¶
PollBufferForMsgs will check if each message is present on the buffer on signal handling sometimes we get extraneous signals on the test process like "urgent I/O condition". This function will ignore any unknown messages in between but check that at least all msgs where received in the provided order (but ignoring unknown messages in between).
func SendUntilMsgIsReceived ¶
SendUntilMsgIsReceived send a signal until the provided messages are read in the output.
Types ¶
type CLI ¶
type CLI struct { Chdir string LogLevel string AppendEnv []string // contains filtered or unexported fields }
CLI is a Terramate CLI runner.
func NewInteropCLI ¶
NewInteropCLI creates a new runner CLI suited for interop tests.
func (CLI) ListChangedStacks ¶
ListChangedStacks is a helper for executing `terramate list --changed`.
func (CLI) ListStacks ¶
ListStacks is a helper for executinh `terramate list`.
func (*CLI) NewRunFixture ¶
func (tm *CLI) NewRunFixture(mode RunMode, rootdir string, flags ...string) RunFixture
NewRunFixture returns a new runFixture ready to be executed which supports 3 execution modes:
In the case of HangRun mode, the steps below will happen:
- The helper `hang` command is invoked.
- The test will poll the stdout buffer waiting for a "ready" message.
- When the process is ready, the testing will send CTRL-C twice and wait for the process acknowledge.
- The test will wait for [hangTimeout] seconds for a graceful exit, otherwise the process is killed with SIGKILL.
In the case of SleepRun mode, the steps below will happen:
- The helper `sleep` command is invoked.
- The test will poll the stdout buffer waiting for a "ready" message.
- When the process is ready, the testing will send a single CTRL-C.
- The test will wait for process graceful exit.
Usage:
cli := NewCli(t, chdir) fixture := NewRunFixture(hangRun, s.RootDir(), "--cloud-sync-deployment") result = fixture.Run() AssertRunResult(t, result, expected)
func (*CLI) PrependToPath ¶
PrependToPath prepend the provided directory to the OS's PATH environment variable in a portable way.
func (CLI) RunWithStdin ¶ added in v0.5.0
RunWithStdin runs the CLI but uses the provided string as stdin.
func (CLI) StacksRunGraph ¶
StacksRunGraph is a helper for executing `terramate experimental run-graph`.
func (CLI) StacksRunOrder ¶
StacksRunOrder is a helper for executing `terramate experimental run-order`.
func (CLI) TriggerStack ¶
TriggerStack is a helper for executing `terramate experimental trigger`.
type Cmd ¶
type Cmd struct { Stdin *buffer Stdout *buffer Stderr *buffer // contains filtered or unexported fields }
Cmd is a generic runner that can be used to run any command.
func (*Cmd) Setpgid ¶
func (tc *Cmd) Setpgid()
Setpgid sets the pgid process attribute. When set, the command will execute in a new process group id.
func (*Cmd) SignalGroup ¶
SignalGroup sends the signal to all processes part of the cmd group.
type RunExpected ¶
type RunExpected struct { Stdout string Stderr string StdoutRegex string StderrRegex string StdoutRegexes []string StderrRegexes []string IgnoreStdout bool IgnoreStderr bool FlattenStdout bool Status int }
RunExpected specifies the expected result for the CLI execution.
type RunFixture ¶
type RunFixture struct { Command []string // contains filtered or unexported fields }
RunFixture defines a runner fixture for specialized modes of run.