testenv

package
v0.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package testenv contains Environment for use in testing.

Index

Constants

View Source
const (
	// TestRepoPassword is a password for repositories created in tests.
	TestRepoPassword = "qWQPJ2hiiLgWRRCr"
)

Variables

View Source
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.

func (*CLIExeRunner) Start added in v0.9.0

func (e *CLIExeRunner) Start(t *testing.T, args []string) (stdout, stderr io.Reader, wait func() error, kill func())

Start implements CLIRunner.

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().

func (*CLIInProcRunner) Start added in v0.9.0

func (e *CLIInProcRunner) Start(t *testing.T, args []string) (stdout, stderr io.Reader, wait func() error, kill func())

Start implements CLIRunner.

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

func NewCLITest(t *testing.T, repoCreateFlags []string, runner CLIRunner) *CLITest

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

func (e *CLITest) RunAndExpectFailure(t *testing.T, args ...string) []string

RunAndExpectFailure runs the given command, expects it to fail and returns its output lines.

func (*CLITest) RunAndExpectSuccess

func (e *CLITest) RunAndExpectSuccess(t *testing.T, args ...string) []string

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) (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

func (e *CLITest) RunAndVerifyOutputLineCount(t *testing.T, wantLines int, args ...string) []string

RunAndVerifyOutputLineCount runs the given command and asserts it returns the given number of output lines, then returns them.

type FakeTimeServer added in v0.7.0

type FakeTimeServer struct {
	Now func() time.Time
}

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL