Documentation ¶
Overview ¶
Package testament provides convinience tools in testing.
Error Helper ¶
The error specific functions are helpers for checking nested errors, or gRPC specific codes.
Network Helpers ¶
These helpers can acquire random free network port.
Randomise Helpers ¶
There are some useful helpers for creating random strings, slices, etc.
Comparer Helpers ¶
These helpers are useful to be used with the google's cmp package.
Index ¶
- Variables
- func AssertInError(t *testing.T, haystack, needle error) bool
- func AssertIsCode(t *testing.T, err error, code codes.Code) bool
- func GetFreeOpenPort(t *testing.T) (uint, net.Listener)
- func GetFreePort(t *testing.T) uint
- func Int32Slice(n int) []int32
- func Int64Slice(n int) []int64
- func IntSlice(n int) []int
- func RandInt32Slice(n int) []int32
- func RandInt64Slice(n int) []int64
- func RandIntSlice(n int) []int
- func RandomEmailAddress() string
- func RandomLowerString(count int) string
- func RandomString(count int) string
- func RandomStringSlice(max int) []string
- func StringSlice(n int) []string
Constants ¶
This section is empty.
Variables ¶
var Int32SliceComparer = cmp.Comparer(func(a, b []int32) bool {
return equal(a, b)
})
Int32SliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted. The slices are copies and can be safely reused.
var Int64SliceComparer = cmp.Comparer(func(a, b []int64) bool {
return equal(a, b)
})
Int64SliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted. The slices are copies and can be safely reused.
var IntSliceComparer = cmp.Comparer(func(a, b []int) bool {
return equal(a, b)
})
IntSliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted. The slices are copies and can be safely reused.
var StringSliceComparer = cmp.Comparer(func(a, b []string) bool {
return equal(a, b)
})
StringSliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted. The slices are copies and can be safely reused.
Functions ¶
func AssertInError ¶
AssertInError returns true if the needle is found in stack, which is created either with pkg/errors help, the multierror or Go's error wrap. It will fall back to checking the contents of the needle.Error() is in haystack.Error().
func AssertIsCode ¶ added in v0.1.0
AssertIsCode is a helper to assert the err error contains the code.
func GetFreeOpenPort ¶ added in v0.1.0
GetFreeOpenPort returns a port that is already claimed. It closes the listener on test cleanup.
func GetFreePort ¶ added in v0.1.0
GetFreePort returns a random open port.
func Int32Slice ¶ added in v0.2.0
Int32Slice returns a slice of int32 elements with provided length.
func Int64Slice ¶ added in v0.2.0
Int64Slice returns a slice of int64 elements with provided length.
func RandInt32Slice ¶ added in v0.2.0
RandInt32Slice returns a slice of int32 elements with random length of less than n.
func RandInt64Slice ¶ added in v0.2.0
RandInt64Slice returns a slice of int64 elements with random length of less than n.
func RandIntSlice ¶ added in v0.2.0
RandIntSlice returns a slice of int elements with random length of less than n.
func RandomEmailAddress ¶ added in v0.2.2
func RandomEmailAddress() string
RandomEmailAddress returns a random email address.
func RandomLowerString ¶ added in v0.2.0
RandomLowerString returns a randomly generates lower-cased string with the length of count.
func RandomString ¶ added in v0.1.0
RandomString returns a randomly generates string with the length of count.
func RandomStringSlice ¶ added in v0.2.0
RandomStringSlice return a random string slice with maximum length of max.
func StringSlice ¶ added in v0.2.0
StringSlice return a string slice with the provided length.
Types ¶
This section is empty.