Documentation
¶
Overview ¶
Package testenv contains Environment for use in testing.
Index ¶
- Constants
- Variables
- type CLIExeRunner
- type CLIInProcRunner
- type CLIRunner
- type CLITest
- func (e *CLITest) NotificationsSent() []*sender.Message
- func (e *CLITest) Run(tb testing.TB, expectedError bool, args ...string) (stdout, stderr []string, err error)
- func (e *CLITest) RunAndExpectFailure(tb testing.TB, args ...string) (stdout, stderr []string)
- func (e *CLITest) RunAndExpectSuccess(tb testing.TB, args ...string) []string
- func (e *CLITest) RunAndExpectSuccessWithErrOut(tb testing.TB, args ...string) (stdout, stderr []string)
- func (e *CLITest) RunAndProcessStderr(tb testing.TB, stderrCallback func(line string) bool, args ...string) (wait func() error, kill func())
- func (e *CLITest) RunAndProcessStderrAsync(tb testing.TB, stderrCallback func(line string) bool, ...) (wait func() error, kill func())
- func (e *CLITest) RunAndProcessStderrInt(tb testing.TB, stderrCallback func(line string) bool, ...) (wait func() error, interrupt func(os.Signal))
- func (e *CLITest) RunAndVerifyOutputLineCount(tb testing.TB, wantLines int, args ...string) []string
- func (e *CLITest) SetLogOutput(enable bool, prefix string)
- func (e *CLITest) TweakFile(tb testing.TB, 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
ExtraFiles []*os.File // this is used for socket-activation tests
LogsDir string
}
CLIExeRunner is a CLIExeRunner that invokes the commands via external executable.
func NewExeRunner ¶ added in v0.9.0
func NewExeRunner(tb testing.TB) *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(tb testing.TB, 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(tb testing.TB, ctx context.Context, args []string, env map[string]string) (stdout, stderr io.Reader, wait func() error, interrupt func(os.Signal))
}
CLIRunner encapsulates running kopia subcommands for testing purposes. It supports implementations that use subprocesses or in-process invocations.
type CLITest ¶
type CLITest struct {
// context in which all subcommands are running
//nolint:containedctx
RunContext context.Context
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) NotificationsSent ¶ added in v0.18.0
func (*CLITest) Run ¶
func (e *CLITest) Run(tb testing.TB, 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(tb testing.TB, 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(tb testing.TB, stderrCallback func(line string) bool, args ...string) (wait func() error, kill func())
RunAndProcessStderr runs the given command, and streams its stderr line-by-line to stderrCallback until it returns false.
func (*CLITest) RunAndProcessStderrAsync ¶ added in v0.19.0
func (e *CLITest) RunAndProcessStderrAsync(tb testing.TB, stderrCallback func(line string) bool, stderrAsyncCallback func(line string), args ...string) (wait func() error, kill func())
RunAndProcessStderrAsync runs the given command, and streams its stderr line-by-line stderrCallback until it returns false.
func (*CLITest) RunAndProcessStderrInt ¶ added in v0.16.0
func (e *CLITest) RunAndProcessStderrInt(tb testing.TB, stderrCallback func(line string) bool, stderrAsyncCallback func(line string), args ...string) (wait func() error, interrupt func(os.Signal))
RunAndProcessStderrInt runs the given command, and streams its stderr line-by-line to stderrCallback until it returns false. The remaining lines from stderr, if any, are asynchronously sent line-by-line to stderrAsyncCallback.
func (*CLITest) RunAndVerifyOutputLineCount ¶
func (e *CLITest) RunAndVerifyOutputLineCount(tb testing.TB, wantLines int, args ...string) []string
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)