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 RandUint32Slice(n int) []uint32
- func RandUint64Slice(n int) []uint64
- func RandUintSlice(n int) []uint
- func RandomEmailAddress() string
- func RandomLowerString(count int) string
- func RandomS3Filename() string
- func RandomString(count int) string
- func RandomStringSlice(to int) []string
- func StringSlice(n int) []string
- func Uint32Slice(n int) []uint32
- func Uint64Slice(n int) []uint64
- func UintSlice(n int) []uint
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.
var Uint32SliceComparer = cmp.Comparer(func(a, b []uint32) bool {
return equal(a, b)
})
Uint32SliceComparer 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 Uint64SliceComparer = cmp.Comparer(func(a, b []uint64) bool {
return equal(a, b)
})
Uint64SliceComparer 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 RandUint32Slice ¶ added in v0.5.0
RandUint32Slice returns a slice of uint32 elements with random length of less than n.
func RandUint64Slice ¶ added in v0.5.0
RandUint64Slice returns a slice of uint64 elements with random length of less than n.
func RandUintSlice ¶ added in v0.5.0
RandUintSlice returns a slice of uint 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 RandomS3Filename ¶ added in v0.4.0
func RandomS3Filename() string
RandomS3Filename returns a random S3 filename with a subfolder.
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 to.
func StringSlice ¶ added in v0.2.0
StringSlice return a string slice with the provided length.
func Uint32Slice ¶ added in v0.5.0
Uint32Slice returns a slice of uint32 elements with provided length.
func Uint64Slice ¶ added in v0.5.0
Uint64Slice returns a slice of uint64 elements with provided length.
Types ¶
This section is empty.