Documentation ¶
Overview ¶
Package test contains utility methods for testing.
Index ¶
- Constants
- Variables
- func ByteSlicesBackedBySameData(a, b []byte) bool
- func CmpMatcher(x interface{}, opts ...cmp.Option) gomock.Matcher
- func ConvertToExtendedOptions(msg proto.Message) (namespace.ExtendedOptions, error)
- func Diff(expected, actual string) string
- func MustPrettyJSONArray(t *testing.T, value xjson.Array) string
- func MustPrettyJSONMap(t *testing.T, value xjson.Map) string
- func MustPrettyJSONString(t *testing.T, str string) string
- func NewController(t require.TestingT) *gomock.Controller
- func NewCorruptingFile(fd xos.File, corruptionProbability float64, seed int64) xos.File
- func NewExtendedOptionsJson(value string) xjson.Map
- func NewExtendedOptionsProto(value string) (*protobuftypes.Any, error)
- func NewLogger(t *testing.T) *zap.Logger
- func NewProtobufAny(msg proto.Message) (*protobuftypes.Any, error)
- type 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 CmpMatcher ¶ added in v0.8.2
CmpMatcher returns a new matcher backed by go-cmp/cmp.Equal.
func ConvertToExtendedOptions ¶ added in v0.15.17
func ConvertToExtendedOptions(msg proto.Message) (namespace.ExtendedOptions, error)
ConvertToExtendedOptions converts protobuf message to ExtendedOptions.
func Diff ¶
Diff is a helper method to print a terminal pretty diff of two strings for test output purposes.
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 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 NewExtendedOptionsJson ¶ added in v0.15.17
NewExtendedOptionsJson returns a json Map with ExtendedOptions as protobuf Any.
func NewExtendedOptionsProto ¶ added in v0.15.17
func NewExtendedOptionsProto(value string) (*protobuftypes.Any, error)
NewExtendedOptionsProto construct a new protobuf Any message with ExtendedOptions.
func NewProtobufAny ¶ added in v0.15.17
func NewProtobufAny(msg proto.Message) (*protobuftypes.Any, error)
NewProtobufAny converts a typed protobuf message into protobuf Any type.
Types ¶
type ExtendedOptions ¶ added in v0.15.17
type ExtendedOptions struct {
// contains filtered or unexported fields
}
ExtendedOptions is a struct for testing namespace ExtendedOptions.
func (*ExtendedOptions) ToProto ¶ added in v0.15.17
func (o *ExtendedOptions) ToProto() (proto.Message, string)
func (*ExtendedOptions) Validate ¶ added in v0.15.17
func (o *ExtendedOptions) Validate() error
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. |