test

package
v0.0.0-...-fd07d66 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-2-Clause-Patent Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(
	t *testing.T, a interface{}, b interface{}, message string)

AssertEqual asserts b is equal to a

Whilst suitable in most situations, reflect.DeepEqual() may not be suitable for nontrivial struct element comparisons, go-cmp should then be used.

func AssertFalse

func AssertFalse(t *testing.T, b bool, message string)

AssertFalse asserts b is false

func AssertNotEqual

func AssertNotEqual(
	t *testing.T, a interface{}, b interface{}, message string)

AssertNotEqual asserts b is not equal to a

Whilst suitable in most situations, reflect.DeepEqual() may not be suitable for nontrivial struct element comparisons, go-cmp should then be used.

func AssertStringsEqual

func AssertStringsEqual(
	t *testing.T, a []string, b []string, message string)

AssertStringsEqual sorts string slices before comparing.

func AssertTrue

func AssertTrue(t *testing.T, b bool, message string)

AssertTrue asserts b is true

func CmpErr

func CmpErr(t *testing.T, want, got error)

CmpErr compares two errors for equality or at least close similarity in their messages.

func CmpErrBool

func CmpErrBool(want, got error) bool

CmpErrBool compares two errors and returns a boolean value indicating equality or at least close similarity between their messages.

func CmpOptEquateErrorMessages

func CmpOptEquateErrorMessages() cmp.Option

CmpOptEquateErrorMessages creates a cmp.Option that allows go-cmp to compare errors by message.

func CmpOptIgnoreFieldAnyType

func CmpOptIgnoreFieldAnyType(field string) cmp.Option

CmpOptIgnoreFieldAnyType creates a cmp.Option that allows go-cmp comparisons to ignore all fields with a specific name in any type.

func Context

func Context(t *testing.T) context.Context

Context returns a context that is canceled when the test is done.

func CopyDir

func CopyDir(t *testing.T, src, dst string)

CopyDir will recursively copy src to test. Fails if src does not exist or dst already exists.

func CopyFile

func CopyFile(t *testing.T, src, dst string)

CopyFile copies the src file to dst. Any existing file will be overwritten and will not copy file attributes.

func CreateTestDir

func CreateTestDir(t *testing.T) (string, func())

CreateTestDir creates a temporary test directory. It returns the path to the directory and a cleanup function.

func CreateTestFile

func CreateTestFile(t *testing.T, dir, content string) string

CreateTestFile creates a file in the given directory with a random name, and writes the content string to the file. It returns the path to the file.

func CreateTestSocket

func CreateTestSocket(t *testing.T, sockPath string) (*net.UnixListener, func())

CreateTestSocket creates a Unix Domain Socket that can listen for connections on a given path. It returns the listener and a cleanup function.

func DefaultCmpOpts

func DefaultCmpOpts() []cmp.Option

DefaultCmpOpts gets default go-cmp comparison options for tests.

func ExpectError

func ExpectError(t *testing.T, actualErr error, expectedMessage string, desc interface{})

ExpectError asserts error contains expected message

func GetIndex

func GetIndex(varIdx ...int32) int32

GetIndex return suitable index value for auto generating mocks.

func LoadTestFiles

func LoadTestFiles(inFile string, outFile string) (
	inputs [][]string, outputs [][]string, err error)

LoadTestFiles reads inputs and outputs from file and do basic sanity checks. Both files contain entries of multiple lines separated by blank line. Return inputs and outputs, both of which are slices of string slices.

func MockHostAddr

func MockHostAddr(varIdx ...int32) *net.TCPAddr

MockHostAddr returns mock tcp addresses for use in tests.

func MockPCIAddr

func MockPCIAddr(varIdx ...int32) string

MockPCIAddr returns mock PCIAddr values for use in tests.

func MockPCIAddrs

func MockPCIAddrs(idxs ...int) (addrs []string)

MockPCIAddrs returns slice of mock PCIAddr values for use in tests.

func MockPoolUUID

func MockPoolUUID(varIdx ...int32) uuid.UUID

MockPoolUUID returns mock pool UUID values for use in tests.

func MockUUID

func MockUUID(varIdx ...int32) string

MockUUID returns mock UUID values for use in tests.

func MockVMDPCIAddr

func MockVMDPCIAddr(dom int32, varIdx ...int32) string

MockVMDPCIAddr returns mock PCIAddr values for use in tests. VMD PCI address domains start at 0x10000 to avoid overlapping with standard ACPI addresses.

func MockVMDPCIAddrs

func MockVMDPCIAddrs(dom int, idxs ...int) (addrs []string)

MockVMDPCIAddrs returns slice of mock VMD PCIAddr values for use in tests.

func MustLogContext

func MustLogContext(t *testing.T, log logging.Logger) context.Context

MustLogContext returns a context containing the supplied logger. Canceled when the test is done.

func SetupTestListener

func SetupTestListener(t *testing.T, conn chan *net.UnixConn) (string, func())

SetupTestListener sets up a Unix Domain Socket in a temp directory to listen and receive one connection. The server-side connection object is sent through the conn channel when a client connects. It returns the path to the socket, to allow the client to connect, and a cleanup function.

func ShowBufferOnFailure

func ShowBufferOnFailure(t *testing.T, buf fmt.Stringer)

ShowBufferOnFailure displays captured output on test failure. Should be run via defer in the test function.

func SplitFile

func SplitFile(path string) (sections [][]string, err error)

SplitFile separates file content into contiguous sections separated by a blank line.

Types

type MockListPoolsResult

type MockListPoolsResult struct {
	Status int32
	Err    error
}

MockListPoolsResult mocks list pool results.

type MockWriter

type MockWriter struct {
	WriteErr error
	// contains filtered or unexported fields
}

MockWriter is a mock io.Writer that can be used to inject errors and check values written.

func (*MockWriter) GetWritten

func (w *MockWriter) GetWritten() string

GetWritten gets the string value written using Write.

func (*MockWriter) Write

func (w *MockWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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