-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
snapshots_test.go
84 lines (63 loc) · 1.49 KB
/
snapshots_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
77
78
79
80
81
82
83
84
package got_test
import (
"os"
"path/filepath"
"testing"
"github.com/ysmood/gop"
"github.com/ysmood/got"
)
func TestSnapshots(t *testing.T) {
g := got.T(t)
type C struct {
Val int
}
g.Snapshot("a", "ok")
g.Snapshot("b", 1)
g.Snapshot("b", 1)
g.Snapshot("c", C{10})
g.Run("sub", func(g got.G) {
g.Snapshot("d", "ok")
})
m := &mock{t: t, name: t.Name()}
gm := got.New(m)
gm.Snapshot("a", "ok")
gm.Snapshot("a", "no")
m.check(`"no" ⦗not ==⦘ "ok"`)
gm.Snapshot("a", map[int]int{1: 2})
g.Has(m.msg, "diff chunk")
m.reset()
gm.ErrorHandler = got.NewDefaultAssertionError(gop.ThemeNone, nil)
gm.Snapshot("a", "no")
m.checkWithStyle(true, `"no" ⦗not ==⦘ "ok"`)
}
func TestSnapshotsCreate(t *testing.T) {
path := filepath.FromSlash(".got/snapshots/TestSnapshotsCreate/a.json")
err := os.RemoveAll(path)
if err != nil {
panic(err)
}
g := got.T(t)
g.Cleanup(func() {
g.True(g.PathExists(path))
})
g.Snapshot("a", "ok")
}
func TestSnapshotsNotUsed(t *testing.T) {
path := filepath.FromSlash(".got/snapshots/TestSnapshotsNotUsed/a.json")
g := got.T(t)
g.WriteFile(path, []byte(`1`))
m := &mock{t: t, name: t.Name()}
got.New(m)
m.cleanup()
g.False(g.PathExists(path))
}
func TestSnapshotsNotUsedWhenFailure(t *testing.T) {
path := filepath.FromSlash(".got/snapshots/TestSnapshotsNotUsedWhenFailure/a.json")
g := got.T(t)
g.WriteFile(path, []byte(`1`))
m := &mock{t: t, name: t.Name()}
gm := got.New(m)
gm.Fail()
m.cleanup()
g.True(g.PathExists(path))
}