testutil

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Contains check.Checker = &containsChecker{
	&check.CheckerInfo{Name: "Contains", Params: []string{"container", "elem"}},
}

Contains is a Checker that looks for a elem in a container. The elem can be any object. The container can be an array, slice or string.

View Source
var DeepContains check.Checker = &deepContainsChecker{
	&check.CheckerInfo{Name: "DeepContains", Params: []string{"container", "elem"}},
}

DeepContains is a Checker that looks for a elem in a container using DeepEqual. The elem can be any object. The container can be an array, slice or string.

View Source
var FileAbsent check.Checker = &filePresenceChecker{
	CheckerInfo: &check.CheckerInfo{Name: "FileAbsent", Params: []string{"filename"}},
	present:     false,
}

FileAbsent verifies that the given file does not exist.

View Source
var FileContains check.Checker = &fileContentChecker{
	CheckerInfo: &check.CheckerInfo{Name: "FileContains", Params: []string{"filename", "contents"}},
}

FileContains verifies that the given file's content contains the string (or fmt.Stringer) or []byte provided.

View Source
var FileEquals check.Checker = &fileContentChecker{
	CheckerInfo: &check.CheckerInfo{Name: "FileEquals", Params: []string{"filename", "contents"}},
	exact:       true,
}

FileEquals verifies that the given file's content is equal to the string (or fmt.Stringer) or []byte provided.

View Source
var FileMatches check.Checker = &fileContentChecker{
	CheckerInfo: &check.CheckerInfo{Name: "FileMatches", Params: []string{"filename", "regex"}},
}

FileMatches verifies that the given file's content matches the string provided.

View Source
var FilePresent check.Checker = &filePresenceChecker{
	CheckerInfo: &check.CheckerInfo{Name: "FilePresent", Params: []string{"filename"}},
	present:     true,
}

FilePresent verifies that the given file exists.

View Source
var IntEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntEqual", Params: []string{"a", "b"}}, rel: "=="}

IntEqual checker verifies that one integer is equal to other integer.

For example:

c.Assert(1, IntEqual, 1)
View Source
var IntGreaterEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntGreaterEqual", Params: []string{"a", "b"}}, rel: ">="}

IntGreaterEqual checker verifies that one integer is greater than or equal to other integer.

For example:

c.Assert(1, IntGreaterEqual, 2)
View Source
var IntGreaterThan = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntGreaterThan", Params: []string{"a", "b"}}, rel: ">"}

IntGreaterThan checker verifies that one integer is greater than other integer.

For example:

c.Assert(2, IntGreaterThan, 1)
View Source
var IntLessEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntLessEqual", Params: []string{"a", "b"}}, rel: "<="}

IntLessEqual checker verifies that one integer is less than or equal to other integer.

For example:

c.Assert(1, IntLessEqual, 1)
View Source
var IntLessThan = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntLessThan", Params: []string{"a", "b"}}, rel: "<"}

IntLessThan checker verifies that one integer is less than other integer.

For example:

c.Assert(1, IntLessThan, 2)
View Source
var IntNotEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntNotEqual", Params: []string{"a", "b"}}, rel: "!="}

IntNotEqual checker verifies that one integer is not equal to other integer.

For example:

c.Assert(1, IntNotEqual, 2)
View Source
var PGPKeys = map[string]*PGPKeyData{
	"key-ubuntu-2018": {
		ID:          "871920D1991BC93C",
		PubKeyArmor: pubKeyUbuntu2018Armor,
	},
	"key1": {
		ID:           "854BAF1AA9D76600",
		PubKeyArmor:  pubKey1Armor,
		PrivKeyArmor: privKey1Armor,
	},
	"key2": {
		ID:           "9568570379BF1F43",
		PubKeyArmor:  pubKey2Armor,
		PrivKeyArmor: privKey2Armor,
	},
}
View Source
var PackageData = map[string][]byte{}

Functions

func MakeDeb

func MakeDeb(entries []TarEntry) ([]byte, error)

func MustMakeDeb added in v0.8.1

func MustMakeDeb(entries []TarEntry) []byte

func PrefixEachLine added in v0.9.0

func PrefixEachLine(text string, prefix string) string

PrefixEachLine indents each line in the provided string with the prefix.

func Reindent

func Reindent(in string) []byte

Reindent deindents the provided string and replaces tabs with spaces so yaml inlined into tests works properly when decoded.

func TreeDump

func TreeDump(dir string) map[string]string

Types

type BaseTest

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

BaseTest is a structure used as a base test suite for many of the pebble tests.

func (*BaseTest) AddCleanup

func (s *BaseTest) AddCleanup(f func())

AddCleanup adds a new cleanup function to the test

func (*BaseTest) SetUpTest

func (s *BaseTest) SetUpTest(c *check.C)

SetUpTest prepares the cleanup

func (*BaseTest) TearDownTest

func (s *BaseTest) TearDownTest(c *check.C)

TearDownTest cleans up the channel.ini files in case they were changed by the test. It also runs the cleanup handlers

type FakeCmd

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

FakeCmd allows faking commands for testing.

func FakeCommand

func FakeCommand(c *check.C, basename, script string) *FakeCmd

FakeCommand adds a faked command. If the basename argument is a command it is added to PATH. If it is an absolute path it is just created there. the caller is responsible for the cleanup in this case.

The command logs all invocations to a dedicated log file. If script is non-empty then it is used as is and the caller is responsible for how the script behaves (exit code and any extra behavior). If script is empty then the command exits successfully without any other side-effect.

func (*FakeCmd) Also

func (cmd *FakeCmd) Also(basename, script string) *FakeCmd

Also fake this command, using the same bindir and log. Useful when you want to check the ordering of things.

func (*FakeCmd) BinDir

func (cmd *FakeCmd) BinDir() string

BinDir returns the location of the directory holding overridden commands.

func (*FakeCmd) Calls

func (cmd *FakeCmd) Calls() [][]string

Calls returns a list of calls that were made to the fake command. of the form:

[][]string{
    {"cmd", "arg1", "arg2"}, // first invocation of "cmd"
    {"cmd", "arg1", "arg2"}, // second invocation of "cmd"
}

func (*FakeCmd) Exe

func (cmd *FakeCmd) Exe() string

Exe return the full path of the fake binary

func (*FakeCmd) ForgetCalls

func (cmd *FakeCmd) ForgetCalls()

ForgetCalls purges the list of calls made so far

func (*FakeCmd) Restore

func (cmd *FakeCmd) Restore()

Restore removes the faked command from PATH

type PGPKeyData added in v0.9.0

type PGPKeyData struct {
	ID           string
	PubKeyArmor  string
	PrivKeyArmor string
	PubKey       *packet.PublicKey
	PrivKey      *packet.PrivateKey
}

type TarEntry

type TarEntry struct {
	Header  tar.Header
	NoFixup bool
	Content []byte
}

func Dir added in v0.8.1

func Dir(mode int64, path string) TarEntry

Dir is a shortcut for creating a directory TarEntry structure (with tar.Typeflag set to tar.TypeDir). Dir stands for "DIRectory".

func Lnk added in v0.8.1

func Lnk(mode int64, path, target string) TarEntry

Lnk is a shortcut for creating a symbolic link TarEntry structure (with tar.Typeflag set to tar.TypeSymlink). Lnk stands for "symbolic LiNK".

func Reg added in v0.8.1

func Reg(mode int64, path, content string) TarEntry

Reg is a shortcut for creating a regular file TarEntry structure (with tar.Typeflag set tar.TypeReg). Reg stands for "REGular file".

Jump to

Keyboard shortcuts

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