testenv

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package testenv contains Environment for use in testing.

Index

Constants

This section is empty.

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
	// 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) Cleanup

func (e *CLITest) Cleanup(t *testing.T)

Cleanup cleans up the test Environment unless the test has failed.

func (*CLITest) ListDirectory

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

ListDirectory lists a given directory 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) Run

func (e *CLITest) Run(t *testing.T, 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
	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
	MaxFileSize            int
	MinNameLength          int
	MaxNameLength          int
}

DirectoryTreeOptions lists options for CreateDirectoryTree

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