utils

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtraCnf          = "EXTRA_MY_CNF"
	BinlogRowImageCnf = "binlog-row-image.cnf"
)

Variables

View Source
var MustMatch = MustMatchFn()

MustMatch is a convenience version of MustMatchFn with no overrides. Usage in Test*() function:

testutils.MustMatch(t, want, got, "something doesn't match")

Functions

func EnsureNoLeaks added in v0.18.0

func EnsureNoLeaks(t testing.TB)

EnsureNoLeaks checks for goroutine and socket leaks and fails the test if any are found.

func GetLeaks added in v0.18.0

func GetLeaks() error

GetLeaks checks for goroutine and socket leaks and returns an error if any are found. One use case is in TestMain()s to ensure that all tests are cleaned up.

func LeakCheckContext added in v0.18.0

func LeakCheckContext(t testing.TB) context.Context

LeakCheckContext returns a Context that will be automatically cancelled at the end of this test. If the test has finished successfully, it will be checked for goroutine leaks after context cancellation.

func LeakCheckContextTimeout added in v0.18.0

func LeakCheckContextTimeout(t testing.TB, timeout time.Duration) context.Context

LeakCheckContextTimeout behaves like LeakCheckContext but the returned Context will be cancelled after `timeout`, or after the test finishes, whichever happens first.

func MakeTestOutput added in v0.15.0

func MakeTestOutput(t *testing.T, dir, pattern string) string

func MustMatchFn

func MustMatchFn(ignoredFields ...string) func(t *testing.T, want, got any, errMsg ...string)

MustMatchFn is used to create a common diff function for a test file Usage in *_test.go file:

Top declaration:

var mustMatch = testutils.MustMatchFn(

[]any{  // types with unexported fields
	type1{},
	type2{},
	...
	typeN{},
},
[]string{  // ignored fields
	".id",        // id numbers are unstable
	".createAt",  // created dates might not be interesting to compare
},

)

In Test*() function:

mustMatch(t, want, got, "something doesn't match")

func MustMatchPB added in v0.11.0

func MustMatchPB(t *testing.T, expected string, pb proto.Message)

func SetBinlogRowImageMode added in v0.17.0

func SetBinlogRowImageMode(mode string, cnfDir string) error

SetBinlogRowImageMode creates a temp cnf file to set binlog_row_image to noblob for vreplication unit tests. It adds it to the EXTRA_MY_CNF environment variable which appends text from them into my.cnf.

Types

This section is empty.

Jump to

Keyboard shortcuts

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