testutil

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 18 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 DeepUnsortedMatches check.Checker = &deepUnsortedMatchChecker{
	&check.CheckerInfo{Name: "DeepUnsortedMatches", Params: []string{"container1", "container2"}},
}

DeepUnsortedMatches checks if two containers contain the same elements in the same number (but possibly different order) using DeepEqual. The container can be an array, a slice or a map.

View Source
var DirEquals check.Checker = &dirContentChecker{
	CheckerInfo: &check.CheckerInfo{Name: "DirEquals", Params: []string{"directory", "contents"}},
}

DirEquals verifies that the given directory contains exactly the given contents. Contents should be a slice of strings of the form "drwxr-xr-x filename".

View Source
var ErrorIs = &errorIsChecker{
	&check.CheckerInfo{Name: "ErrorIs", Params: []string{"error", "target"}},
}

ErrorIs calls errors.Is with the provided arguments.

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 JsonEquals check.Checker = &jsonEqualChecker{
	&check.CheckerInfo{Name: "JsonEqual", Params: []string{"obtained", "expected"}},
}

JsonEquals compares the obtained and expected values after having serialized them to JSON and deserialized to a generic any type. This avoids trouble comparing types with unexported fields that otherwise would be problematic to set in external packages.

View Source
var SymlinkTargetContains check.Checker = &symlinkTargetChecker{
	CheckerInfo: &check.CheckerInfo{Name: "SymlinkTargetContains", Params: []string{"filename", "target"}},
}

SymlinkTargetContains verifies that the given file is a symbolic link whose target contains the provided text.

View Source
var SymlinkTargetEquals check.Checker = &symlinkTargetChecker{
	CheckerInfo: &check.CheckerInfo{Name: "SymlinkTargetEquals", Params: []string{"filename", "target"}},
	exact:       true,
}

SymlinkTargetEquals verifies that the given file is a symbolic link with the given target.

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

SymlinkTargetMatches verifies that the given file is a symbolic link whose target matches the provided regular expression.

Functions

func Backup

func Backup(mockablesByPtr ...any) (restore func())

Backup the specified list of elements before further mocking.

func FakeFunc

func FakeFunc[Func any](mock Func, original *Func) (restore func())

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 workshop 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

Jump to

Keyboard shortcuts

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