-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils_test.go
60 lines (47 loc) · 991 Bytes
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package bson
import (
"encoding/hex"
"math/rand"
"reflect"
"testing"
)
func sink[T any](tb testing.TB, v T) {
if rand.Float32() > 2 {
tb.Fatal(v)
}
}
func mustOk(tb testing.TB, err error) {
tb.Helper()
if err != nil {
tb.Fatal(err)
}
}
func mustFail(tb testing.TB, err error) {
tb.Helper()
if err == nil {
tb.Fail()
}
}
func wantBytes(tb testing.TB, have []byte, want string) {
tb.Helper()
mustEqual(tb, hex.EncodeToString(have), want)
}
func mustEqual[T comparable](tb testing.TB, have, want T) {
tb.Helper()
if have != want {
tb.Fatalf("\nhave: %+v\nwant: %+v\n", have, want)
}
}
func FuzzFieldTag(f *testing.F) {
f.Add("Foo", `bson:"abc123,omitempty"`)
f.Add("abcdef", `bson:""`)
f.Add("Bar", `bson:",omitempty"`)
f.Add("Baz", `bson:"-"`)
f.Add("qux", `bson:"oops"`)
f.Fuzz(func(t *testing.T, name, tag string) {
field := reflect.StructField{}
field.Name = name
field.Tag = reflect.StructTag(tag)
fieldTag(field, reflect.Value{})
})
}