Documentation ¶
Index ¶
- func AssertEqual(t *testing.T, a interface{}, b interface{}, message string)
- func AssertFalse(t *testing.T, b bool, message string)
- func AssertNotEqual(t *testing.T, a interface{}, b interface{}, message string)
- func AssertStringsEqual(t *testing.T, a []string, b []string, message string)
- func AssertTrue(t *testing.T, b bool, message string)
- func CmpErr(t *testing.T, want, got error)
- func CmpErrBool(want, got error) bool
- func CmpOptEquateErrorMessages() cmp.Option
- func CmpOptIgnoreFieldAnyType(field string) cmp.Option
- func Context(t *testing.T) context.Context
- func CopyDir(t *testing.T, src, dst string)
- func CopyFile(t *testing.T, src, dst string)
- func CreateTestDir(t *testing.T) (string, func())
- func CreateTestFile(t *testing.T, dir, content string) string
- func CreateTestSocket(t *testing.T, sockPath string) (*net.UnixListener, func())
- func DefaultCmpOpts() []cmp.Option
- func ExpectError(t *testing.T, actualErr error, expectedMessage string, desc interface{})
- func GetIndex(varIdx ...int32) int32
- func LoadTestFiles(inFile string, outFile string) (inputs [][]string, outputs [][]string, err error)
- func MockHostAddr(varIdx ...int32) *net.TCPAddr
- func MockPCIAddr(varIdx ...int32) string
- func MockPCIAddrs(idxs ...int) (addrs []string)
- func MockPoolUUID(varIdx ...int32) uuid.UUID
- func MockUUID(varIdx ...int32) string
- func MockVMDPCIAddr(dom int32, varIdx ...int32) string
- func MockVMDPCIAddrs(dom int, idxs ...int) (addrs []string)
- func MustLogContext(t *testing.T, log logging.Logger) context.Context
- func SetupTestListener(t *testing.T, conn chan *net.UnixConn) (string, func())
- func ShowBufferOnFailure(t *testing.T, buf fmt.Stringer)
- func SplitFile(path string) (sections [][]string, err error)
- type MockListPoolsResult
- type MockWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqual ¶
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 ¶
AssertFalse asserts b is false
func AssertNotEqual ¶
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 ¶
AssertStringsEqual sorts string slices before comparing.
func AssertTrue ¶
AssertTrue asserts b is true
func CmpErr ¶
CmpErr compares two errors for equality or at least close similarity in their messages.
func CmpErrBool ¶
CmpErrBool compares two errors and returns a boolean value indicating equality or at least close similarity between their messages.
func CmpOptEquateErrorMessages ¶
CmpOptEquateErrorMessages creates a cmp.Option that allows go-cmp to compare errors by message.
func CmpOptIgnoreFieldAnyType ¶
CmpOptIgnoreFieldAnyType creates a cmp.Option that allows go-cmp comparisons to ignore all fields with a specific name in any type.
func CopyDir ¶
CopyDir will recursively copy src to test. Fails if src does not exist or dst already exists.
func CopyFile ¶
CopyFile copies the src file to dst. Any existing file will be overwritten and will not copy file attributes.
func CreateTestDir ¶
CreateTestDir creates a temporary test directory. It returns the path to the directory and a cleanup function.
func CreateTestFile ¶
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 ¶
DefaultCmpOpts gets default go-cmp comparison options for tests.
func ExpectError ¶
ExpectError asserts error contains expected message
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 ¶
MockHostAddr returns mock tcp addresses for use in tests.
func MockPCIAddr ¶
MockPCIAddr returns mock PCIAddr values for use in tests.
func MockPCIAddrs ¶
MockPCIAddrs returns slice of mock PCIAddr values for use in tests.
func MockPoolUUID ¶
MockPoolUUID returns mock pool UUID values for use in tests.
func MockVMDPCIAddr ¶
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 ¶
MockVMDPCIAddrs returns slice of mock VMD PCIAddr values for use in tests.
func MustLogContext ¶
MustLogContext returns a context containing the supplied logger. Canceled when the test is done.
func SetupTestListener ¶
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 ¶
ShowBufferOnFailure displays captured output on test failure. Should be run via defer in the test function.
Types ¶
type MockListPoolsResult ¶
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.