testenv

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: Apache-2.0 Imports: 23 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

This section is empty.

Functions

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError fails the test if a given error is not nil.

func CheckNoError

func CheckNoError(t *testing.T, err error)

CheckNoError fails the test if a given error is not nil.

func CreateDirectoryTree

func CreateDirectoryTree(dirname string, options DirectoryTreeOptions, counters *DirectoryTreeCounters) error

CreateDirectoryTree creates a directory tree of a given depth with random files.

func CreateRandomFile

func CreateRandomFile(filePath string, options DirectoryTreeOptions, counters *DirectoryTreeCounters) error

CreateRandomFile creates a new file at the provided path with randomized contents.

func MustCreateDirectoryTree

func MustCreateDirectoryTree(t *testing.T, dirname string, options DirectoryTreeOptions)

MustCreateDirectoryTree creates a directory tree of a given depth with random files.

func MustCreateRandomFile

func MustCreateRandomFile(t *testing.T, filePath string, options DirectoryTreeOptions, counters *DirectoryTreeCounters)

MustCreateRandomFile creates a new file at the provided path with randomized contents. It will fail with a test error if the creation does not succeed.

Types

type CLITest

type CLITest struct {
	RepoDir   string
	ConfigDir string
	Exe       string

	Environment []string

	DefaultRepositoryCreateFlags []string

	PassthroughStderr bool // this is for debugging only

	NextCommandStdin io.Reader // this is used for stdin source tests

	LogsDir string
	// contains filtered or unexported fields
}

CLITest encapsulates state for a CLI-based test.

func NewCLITest

func NewCLITest(t *testing.T) *CLITest

NewCLITest creates a new instance of *CLITest.

func (*CLITest) ListDirectory

func (e *CLITest) ListDirectory(t *testing.T, targets ...string) []DirEntry

ListDirectory lists a given directory and returns directory entries.

func (*CLITest) ListDirectoryRecursive added in v0.8.0

func (e *CLITest) ListDirectoryRecursive(t *testing.T, targets ...string) []DirEntry

ListDirectoryRecursive lists a given directory recursively and returns directory entries.

func (*CLITest) ListSnapshotsAndExpectSuccess

func (e *CLITest) ListSnapshotsAndExpectSuccess(t *testing.T, targets ...string) []SourceInfo

ListSnapshotsAndExpectSuccess lists given snapshots and parses the output.

func (*CLITest) RemoveDefaultPassword added in v0.8.0

func (e *CLITest) RemoveDefaultPassword()

RemoveDefaultPassword prevents KOPIA_PASSWORD from being passed to kopia.

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) *exec.Cmd

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 DirEntry

type DirEntry struct {
	Name     string
	ObjectID string
}

DirEntry represents directory entry.

type DirectoryTreeCounters

type DirectoryTreeCounters struct {
	Files         int
	Directories   int
	Symlinks      int
	TotalFileSize int64
	MaxFileSize   int64
}

DirectoryTreeCounters stores stats about files and directories created by CreateDirectoryTree.

type DirectoryTreeOptions

type DirectoryTreeOptions struct {
	Depth                              int
	MaxSubdirsPerDirectory             int
	MaxFilesPerDirectory               int
	MaxSymlinksPerDirectory            int
	MaxFileSize                        int
	MinNameLength                      int
	MaxNameLength                      int
	NonExistingSymlinkTargetPercentage int // 0..100
}

DirectoryTreeOptions lists options for CreateDirectoryTree.

func MaybeSimplifyFilesystem added in v0.8.0

func MaybeSimplifyFilesystem(o DirectoryTreeOptions) DirectoryTreeOptions

MaybeSimplifyFilesystem applies caps to the provided DirectoryTreeOptions to reduce test time on ARM.

type FakeTimeServer added in v0.7.0

type FakeTimeServer struct {
	// contains filtered or unexported fields
}

FakeTimeServer serves fake time signal to instances of Kopia.

func NewFakeTimeServer added in v0.7.0

func NewFakeTimeServer(startTime time.Time, step time.Duration) *FakeTimeServer

NewFakeTimeServer creates new time server that serves time over HTTP and locally.

func (*FakeTimeServer) Now added in v0.7.0

func (s *FakeTimeServer) Now() time.Time

Now returns current fake time.

func (*FakeTimeServer) ServeHTTP added in v0.7.0

func (s *FakeTimeServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SnapshotInfo

type SnapshotInfo struct {
	ObjectID   string
	SnapshotID string
	Time       time.Time
}

SnapshotInfo represents a single snapshot information.

type SourceInfo

type SourceInfo struct {
	User      string
	Host      string
	Path      string
	Snapshots []SnapshotInfo
}

SourceInfo reprents a single source (user@host:/path) with its snapshots.

Jump to

Keyboard shortcuts

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