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) []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) (kill func())
- func (e *CLITest) RunAndVerifyOutputLineCount(t *testing.T, wantLines int, args ...string) []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 Environment []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.
func (*CLIExeRunner) RemoveDefaultPassword ¶ added in v0.9.0
func (e *CLIExeRunner) RemoveDefaultPassword()
RemoveDefaultPassword prevents KOPIA_PASSWORD from being passed to kopia.
type CLIInProcRunner ¶ added in v0.9.0
type CLIInProcRunner struct { RepoPassword string CustomizeApp func(a *cli.App, kp *kingpin.Application) }
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().
type CLIRunner ¶ added in v0.9.0
type CLIRunner interface {
Start(t *testing.T, args []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 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.
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)