Documentation ¶
Index ¶
- Variables
- func AssertEqualBytes(t *testing.T, expected, actual []byte)
- func AssertEqualJSON(t *testing.T, expected, actual []byte)
- func IsNonWord(c rune) bool
- func MapFromStruct(v interface{}) (ret map[string]interface{})
- func MapOmit(v map[string]interface{}, keys ...string) map[string]interface{}
- func MarshalTextOrJSON(v interface{}) ([]byte, error)
- func MaskAsAsterisk(v []byte) []byte
- func MaskString(v string, as rune, keep func(c rune) bool) string
- func MaskWordAsAsterisk(v []byte) []byte
- func Match(t *testing.T, actual interface{}, opts ...Option)
- func MatchJSON(t *testing.T, actual interface{}, opts ...Option)
- func ResetDefaults()
- func TransformJSON(v interface{}) interface{}
- func TransformSchema(v interface{}) interface{}
- type AssertEqual
- type Clean
- type Marshal
- type Option
- func OptionAssertEqual(assertEqual AssertEqual) Option
- func OptionClean(clean ...Clean) Option
- func OptionCleanRegex(clean Clean, patterns ...string) Option
- func OptionCleanRegexMask(patterns ...string) Option
- func OptionExt(ext string) Option
- func OptionKey(key string) Option
- func OptionMarshal(marshal func(interface{}) ([]byte, error)) Option
- func OptionSkip(skip int) Option
- func OptionTransform(transform func(interface{}) interface{}) Option
- func OptionUpdate(v bool) Option
- type Options
- type Transform
Constants ¶
This section is empty.
Variables ¶
var DefaultUpdate bool
DefaultUpdate option
Functions ¶
func AssertEqualBytes ¶ added in v0.3.0
AssertEqualBytes compare each byte
func AssertEqualJSON ¶ added in v0.3.0
AssertEqualJSON compare value as json, output more human friendly error for json.
func MapFromStruct ¶ added in v0.3.0
func MapFromStruct(v interface{}) (ret map[string]interface{})
MapFromStruct convert struct to map. returns nil if input value is not a struct.
func MarshalTextOrJSON ¶ added in v0.3.0
MarshalTextOrJSON marshal json if value not text.
func MaskAsAsterisk ¶ added in v0.5.1
MaskAsAsterisk treat data as string and replace all characters to `*`.
func MaskString ¶ added in v0.5.1
MaskString replace all runes that not keep to given rune.
func MaskWordAsAsterisk ¶ added in v0.6.0
MaskWordAsAsterisk treat data as string and replace all word characters to `*`.
func TransformJSON ¶ added in v0.3.0
func TransformJSON(v interface{}) interface{}
TransformJSON convert go object to json friendly data format. like mongo-compass used to edit document, types that json not support will be wrapped as { "$"+type: value }.
func TransformSchema ¶ added in v0.3.0
func TransformSchema(v interface{}) interface{}
TransformSchema that only keep type info. Useful when handling dynamic data like timestamp.
Returns:
nil when value is nil $[]byte when value is byte slice $[length]byte when value is byte array {"$array": interface{}} when value is slice or array and all element schema is deep equal. []interface{} when value is slice or array {"$pointer": value } when value is potinter {"$"+type: map[string]interace{}} when value is struct and has any exported fields. map[string]interace{} when value is map "$"+type default
Types ¶
type AssertEqual ¶ added in v0.3.0
AssertEqual fails test if snapshot not equal with actual value.
var DefaultAssertEqual AssertEqual
DefaultAssertEqual option
type Clean ¶ added in v0.5.1
Clean data before compare.
func CleanRegex ¶ added in v0.5.1
CleanRegex clean all data matched by given regexp. If regexp has group, clean function called on all submatch, otherwise, it called on match.
func CleanString ¶ added in v0.5.1
CleanString by a function that takes string as argument
type Marshal ¶ added in v0.3.0
Marshal go object to bytes
var DefaultMarshal Marshal
DefaultMarshal option
type Option ¶
type Option func(*Options)
Option mutate SnapshotOptions
func OptionAssertEqual ¶ added in v0.3.0
func OptionAssertEqual(assertEqual AssertEqual) Option
OptionAssertEqual do assert
func OptionClean ¶ added in v0.5.1
OptionClean dynamic data to make result deterministic. multiple clean option take affect in order.
func OptionCleanRegex ¶ added in v0.5.1
OptionCleanRegex replace all patten match by clean function, panic if any pattern is invalid.
func OptionCleanRegexMask ¶ added in v0.5.1
OptionCleanRegexMask mask word matched by patterns to '*', panic if any pattern is invalid.
func OptionMarshal ¶
OptionMarshal object to bytes.
func OptionTransform ¶
func OptionTransform(transform func(interface{}) interface{}) Option
OptionTransform object before marshal.