-
Notifications
You must be signed in to change notification settings - Fork 0
/
snap_test.go
76 lines (62 loc) · 1.3 KB
/
snap_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package snap_test
import (
"fmt"
"strconv"
"testing"
"time"
"github.com/KasonBraley/snap"
)
func TestSnapDiff(t *testing.T) {
checkAddition := func(x int, y int, want *snap.Snapshot) {
got := x + y
want.Diff(strconv.Itoa(got))
}
checkAddition(2, 2, snap.Snap(t, "4"))
}
func TestSnapInlineIgnore(t *testing.T) {
check := func(want *snap.Snapshot) {
want.Diff(fmt.Sprintf("the current Unix ms time is %d ms", time.Now().UnixMilli()))
}
check(snap.Snap(t, "the current Unix ms time is <snap:ignore> ms"))
}
func TestSnapJSON(t *testing.T) {
checkJSON := func(want *snap.Snapshot) {
type person struct {
Name string `json:"name"`
Age uint `json:"age"`
ignoredField string
}
p := person{
Name: "Doug",
Age: 20,
ignoredField: "bar",
}
want.DiffJSON(&p, " ")
}
checkJSON(
snap.Snap(t, `{
"name": "Doug",
"age": 20
}`))
}
func TestSnapJSONWithIgnore(t *testing.T) {
checkJSON := func(want *snap.Snapshot) {
type person struct {
Name string `json:"name"`
Age uint `json:"age"`
Time time.Time `json:"timestamp"`
}
p := person{
Name: "Doug",
Age: 20,
Time: time.Now(),
}
want.DiffJSON(&p, " ")
}
checkJSON(
snap.Snap(t, `{
"name": "Doug",
"age": 20,
"timestamp": "<snap:ignore>"
}`))
}