Documentation
¶
Overview ¶
Package test contains utility methods for testing.
Index ¶
- Constants
- Variables
- func ByteSlicesBackedBySameData(a, b []byte) bool
- func BytesArray(strings ...string) [][]byte
- func CmpMatcher(x interface{}, opts ...cmp.Option) gomock.Matcher
- func ConvertToTestExtendedOptions(opts *protobuftypes.Struct) (namespace.ExtendedOptions, error)
- func Diff(expected, actual string) string
- func FailNowPanicsTestingT(t *testing.T) require.TestingT
- func MustPrettyJSONArray(t require.TestingT, value xjson.Array) string
- func MustPrettyJSONMap(t require.TestingT, value xjson.Map) string
- func MustPrettyJSONObject(t require.TestingT, value interface{}) string
- func MustPrettyJSONString(t require.TestingT, str string) string
- func NewController(t require.TestingT) *gomock.Controller
- func NewCorruptingFile(fd xos.File, corruptionProbability float64, seed int64) xos.File
- func NewLogger(t require.TestingT) *zap.Logger
- func NewTestExtendedOptionsJSON(value string) xjson.Map
- func NewTestExtendedOptionsProto(value string) *nsproto.ExtendedOptions
- type Reporter
Constants ¶
const TypeURLPrefix = "testm3db.io/"
TypeURLPrefix is a type URL prefix for storing in protobuf Any messages.
Variables ¶
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 ¶
ByteSlicesBackedBySameData returns a bool indicating if the raw backing bytes under the []byte slice point to the same memory.
func BytesArray ¶ added in v1.4.2
BytesArray converts a variable length string arguments (array of strings) into an array of byte arrays
func CmpMatcher ¶ added in v0.8.2
CmpMatcher returns a new matcher backed by go-cmp/cmp.Equal.
func ConvertToTestExtendedOptions ¶ added in v1.2.0
func ConvertToTestExtendedOptions( opts *protobuftypes.Struct, ) (namespace.ExtendedOptions, error)
ConvertToTestExtendedOptions is ExtendedOptsConverter for testExtendedOptions.
func Diff ¶
Diff is a helper method to print a terminal pretty diff of two strings for test output purposes.
func FailNowPanicsTestingT ¶ added in v1.6.0
FailNowPanicsTestingT returns a TestingT that panics on a failed assertion. This is useful for aborting a test on failed assertions from an asynchronous goroutine (since stretchr calls FailNow on testing.T but it will not abort the test unless the goroutine is the one running the benchmark or test). For more info see: https://github.com/stretchr/testify/issues/652.
func MustPrettyJSONArray ¶ added in v1.0.0
MustPrettyJSONArray returns an indented JSON string of the object.
func MustPrettyJSONMap ¶ added in v0.15.0
MustPrettyJSONMap returns an indented JSON string of the object.
func MustPrettyJSONObject ¶ added in v1.6.0
MustPrettyJSONObject returns an indented JSON string of the object.
func MustPrettyJSONString ¶ added in v0.15.0
MustPrettyJSONString returns an indented version of the JSON.
func NewController ¶ added in v0.15.0
func NewController(t require.TestingT) *gomock.Controller
NewController provides a gomock.Controller wrapped with a xtest.Reporter, which gives more useful error modes on unexpected mock calls. See xtest.Reporter for more context.
func NewCorruptingFile ¶ added in v0.4.8
NewCorruptingFile creates a new corrupting file.
func NewTestExtendedOptionsJSON ¶ added in v1.2.0
NewTestExtendedOptionsJSON returns a json Map for testExtendedOptions.
func NewTestExtendedOptionsProto ¶ added in v1.2.0
func NewTestExtendedOptionsProto(value string) *nsproto.ExtendedOptions
NewTestExtendedOptionsProto construct a new protobuf ExtendedOptions message.
Types ¶
type Reporter ¶ added in v0.8.2
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
}
}
Source Files
¶
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. |