test

package
Version: v0.0.0-...-9649366 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package test contains utility methods for testing.

Index

Constants

This section is empty.

Variables

View Source
var IdentTransformer = cmp.Transformer("",
	func(id ident.ID) ident.BytesID { return ident.BytesID(id.Bytes()) })

IdentTransformer transforms any ident.ID into ident.BytesID to make it easier for comparison.

Functions

func ByteSlicesBackedBySameData

func ByteSlicesBackedBySameData(a, b []byte) bool

ByteSlicesBackedBySameData returns a bool indicating if the raw backing bytes under the []byte slice point to the same memory.

func CmpMatcher

func CmpMatcher(x interface{}, opts ...cmp.Option) gomock.Matcher

CmpMatcher returns a new matcher backed by go-cmp/cmp.Equal.

func Diff

func Diff(expected, actual string) string

Diff is a helper method to print a terminal pretty diff of two strings for test output purposes.

func NewCorruptingFile

func NewCorruptingFile(
	fd xos.File,
	corruptionProbability float64,
	seed int64,
) xos.File

NewCorruptingFile creates a new corrupting file.

func NewLogger

func NewLogger(t *testing.T) *zap.Logger

NewLogger returns a new test logger.

Types

type Reporter

type Reporter struct {
	T *testing.T
}

Reporter wraps a *testing.T, and provides a more useful failure mode when interacting with gomock.Controller.

For example, consider:

func TestMyThing(t *testing.T) {
  mockCtrl := gomock.NewController(t)
  defer mockCtrl.Finish()
  mockObj := something.NewMockMyInterface(mockCtrl)
  go func() {
    mockObj.SomeMethod(4, "blah")
  }
}

It hangs without any indication that it's missing an EXPECT() on `mockObj`. Providing the Reporter to the gomock.Controller ctor avoids this, and terminates with useful feedback. i.e.

func TestMyThing(t *testing.T) {
  mockCtrl := gomock.NewController(test.Reporter{t})
  defer mockCtrl.Finish()
  mockObj := something.NewMockMyInterface(mockCtrl)
  go func() {
    mockObj.SomeMethod(4, "blah") // crashes the test now
  }
}

func (Reporter) Errorf

func (r Reporter) Errorf(format string, args ...interface{})

Errorf is equivalent testing.T.Errorf.

func (Reporter) Fatalf

func (r Reporter) Fatalf(format string, args ...interface{})

Fatalf crashes the program with a panic to allow users to diagnose missing expects.

Directories

Path Synopsis
Package testmarshal provides some assertions around marshalling/unmarshalling (serialization/deserialization) behavior for types.
Package testmarshal provides some assertions around marshalling/unmarshalling (serialization/deserialization) behavior for types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL