-
Notifications
You must be signed in to change notification settings - Fork 2
/
global_defaults_test.go
52 lines (42 loc) · 1.81 KB
/
global_defaults_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
package golden_test
import (
"github.com/franiglesias/golden"
"github.com/franiglesias/golden/internal/vfs"
"testing"
)
func TestGlobalDefaults(t *testing.T) {
// fs is kind of an in-memory filesystem. This allows us to test the library
// without polluting the local file system with temporary files. This also allows
// us to inspect the generated paths and files
var fs *vfs.MemFs
setUp := func(t *testing.T) {
// Passing t in each setup guarantees that we are using the right name for the
// snapshot, otherwise the name won't be accurate
// Inits a new instance of Golden using an in-memory filesystem that will be
// empty on each test run
fs = vfs.NewMemFs()
golden.G = golden.NewUsingFs(fs)
}
t.Run("should use defaults defined folder in all tests", func(t *testing.T) {
setUp(t)
golden.Defaults(golden.Folder("__snapshots"))
golden.Verify(t, "first subject.", golden.Snapshot("example-1"))
golden.Verify(t, "second subject.", golden.Snapshot("example-2"))
vfs.AssertSnapshotWasCreated(t, fs, "__snapshots/example-1.snap")
vfs.AssertSnapshotWasCreated(t, fs, "__snapshots/example-2.snap")
})
t.Run("should use defaults defined extension in all tests", func(t *testing.T) {
setUp(t)
golden.Defaults(golden.Extension(".snapshot"))
golden.Verify(t, "first subject.", golden.Snapshot("example-1"))
golden.Verify(t, "second subject.", golden.Snapshot("example-2"))
vfs.AssertSnapshotWasCreated(t, fs, "testdata/example-1.snapshot")
vfs.AssertSnapshotWasCreated(t, fs, "testdata/example-2.snapshot")
})
t.Run("should not allow set default snapshot name", func(t *testing.T) {
setUp(t)
golden.Defaults(golden.Snapshot("example"))
golden.Verify(t, "example subject.")
vfs.AssertSnapshotWasCreated(t, fs, "testdata/TestGlobalDefaults/should_not_allow_set_default_snapshot_name.snap")
})
}