testenv

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 27 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
	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(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) Start added in v0.9.0

func (e *CLIExeRunner) Start(t *testing.T, args []string, env map[string]string) (stdout, stderr io.Reader, wait func() error, interrupt func(os.Signal))

Start implements CLIRunner.

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.

func (*CLIInProcRunner) Start added in v0.9.0

func (e *CLIInProcRunner) Start(t *testing.T, args []string, env map[string]string) (stdout, stderr io.Reader, wait func() error, interrupt func(os.Signal))

Start implements CLIRunner.

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, 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 {
	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

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) (stdout, stderr []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) (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) RunAndProcessStderrInt added in v0.16.0

func (e *CLITest) RunAndProcessStderrInt(t *testing.T, outputCallback func(line string) bool, args ...string) (wait func() error, interrupt func(os.Signal))

RunAndProcessStderrInt runs the given command, and streams its output line-by-line to outputCallback 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.

func (*CLITest) SetLogOutput added in v0.13.0

func (e *CLITest) SetLogOutput(enable bool, prefix string)

func (*CLITest) TweakFile added in v0.13.0

func (e *CLITest) TweakFile(t *testing.T, dirn, fglob string)

TweakFile writes a xor-ed byte at a random point in a file. Used to simulate file corruption.

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