Documentation ¶
Overview ¶
Package testenv contains Environment for use in testing.
Index ¶
- Constants
- Variables
- type CLIExeRunner
- type CLIInProcRunner
- type CLIRunner
- type CLITest
- func (e *CLITest) Run(t *testing.T, expectedError bool, args ...string) (stdout, stderr []string, err error)
- func (e *CLITest) RunAndExpectFailure(t *testing.T, args ...string) (stdout, stderr []string)
- func (e *CLITest) RunAndExpectSuccess(t *testing.T, args ...string) []string
- func (e *CLITest) RunAndExpectSuccessWithErrOut(t *testing.T, args ...string) (stdout, stderr []string)
- func (e *CLITest) RunAndProcessStderr(t *testing.T, callback func(line string) bool, args ...string) (wait func() error, kill func())
- func (e *CLITest) RunAndVerifyOutputLineCount(t *testing.T, wantLines int, args ...string) []string
- func (e *CLITest) SetLogOutput(enable bool, prefix string)
- func (e *CLITest) TweakFile(t *testing.T, dirn, fglob string)
- type FakeTimeServer
Constants ¶
const (
// TestRepoPassword is a password for repositories created in tests.
TestRepoPassword = "qWQPJ2hiiLgWRRCr"
)
Variables ¶
var RepoFormatNotImportant []string
RepoFormatNotImportant chooses arbitrary format version where it's not important to the test.
Functions ¶
This section is empty.
Types ¶
type CLIExeRunner ¶ added in v0.9.0
type CLIExeRunner struct { Exe string PassthroughStderr bool // this is for debugging only NextCommandStdin io.Reader // this is used for stdin source tests LogsDir string }
CLIExeRunner is a CLIExeRunner that invokes the commands via external executable.
func NewExeRunner ¶ added in v0.9.0
func NewExeRunner(t *testing.T) *CLIExeRunner
NewExeRunner returns a CLIRunner that will execute kopia commands by launching subprocesses for each. The kopia executable must be passed via KOPIA_EXE environment variable. The test will be skipped if it's not provided (unless running inside an IDE in which case system-wide `kopia` will be used by default).
func NewExeRunnerWithBinary ¶ added in v0.9.0
func NewExeRunnerWithBinary(t *testing.T, exe string) *CLIExeRunner
NewExeRunnerWithBinary returns a CLIRunner that will execute kopia commands by launching subprocesses for each.
type CLIInProcRunner ¶ added in v0.9.0
type CLIInProcRunner struct { CustomizeApp func(a *cli.App, kp *kingpin.Application) // contains filtered or unexported fields }
CLIInProcRunner is a CLIRunner that invokes provided commands in the current process.
func NewInProcRunner ¶ added in v0.9.0
func NewInProcRunner(t *testing.T) *CLIInProcRunner
NewInProcRunner returns a runner that executes CLI subcommands in the current process using cli.RunSubcommand().
func (*CLIInProcRunner) SetNextStdin ¶ added in v0.11.3
func (e *CLIInProcRunner) SetNextStdin(stdin io.Reader)
SetNextStdin sets the stdin to be used on next command execution.
type CLIRunner ¶ added in v0.9.0
type CLIRunner interface {
Start(t *testing.T, args []string, env map[string]string) (stdout, stderr io.Reader, wait func() error, kill func())
}
CLIRunner encapsulates running kopia subcommands for testing purposes. It supports implementations that use subprocesses or in-process invocations.
type CLITest ¶
type CLITest struct { RepoDir string ConfigDir string Runner CLIRunner Environment map[string]string DefaultRepositoryCreateFlags []string // contains filtered or unexported fields }
CLITest encapsulates state for a CLI-based test.
func NewCLITest ¶
NewCLITest creates a new instance of *CLITest.
func (*CLITest) Run ¶
func (e *CLITest) Run(t *testing.T, expectedError bool, args ...string) (stdout, stderr []string, err error)
Run executes kopia with given arguments and returns the output lines.
func (*CLITest) RunAndExpectFailure ¶
RunAndExpectFailure runs the given command, expects it to fail and returns its output lines.
func (*CLITest) RunAndExpectSuccess ¶
RunAndExpectSuccess runs the given command, expects it to succeed and returns its output lines.
func (*CLITest) RunAndExpectSuccessWithErrOut ¶
func (e *CLITest) RunAndExpectSuccessWithErrOut(t *testing.T, args ...string) (stdout, stderr []string)
RunAndExpectSuccessWithErrOut runs the given command, expects it to succeed and returns its stdout and stderr lines.
func (*CLITest) RunAndProcessStderr ¶
func (e *CLITest) RunAndProcessStderr(t *testing.T, callback func(line string) bool, args ...string) (wait func() error, kill func())
RunAndProcessStderr runs the given command, and streams its output line-by-line to a given function until it returns false.
func (*CLITest) RunAndVerifyOutputLineCount ¶
RunAndVerifyOutputLineCount runs the given command and asserts it returns the given number of output lines, then returns them.
func (*CLITest) SetLogOutput ¶ added in v0.13.0
type FakeTimeServer ¶ added in v0.7.0
FakeTimeServer serves fake time signal to instances of Kopia.
func NewFakeTimeServer ¶ added in v0.7.0
func NewFakeTimeServer(now func() time.Time) *FakeTimeServer
NewFakeTimeServer creates new time server that serves time over HTTP and locally.
func (*FakeTimeServer) ServeHTTP ¶ added in v0.7.0
func (s *FakeTimeServer) ServeHTTP(w http.ResponseWriter, r *http.Request)