This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fixture_test.go
81 lines (66 loc) · 1.47 KB
/
fixture_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
package test
import (
"fmt"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_makeFixturePath(t *testing.T) {
require.Equal(t, makeFixturePath(t, ""), "testdata/output/Test_makeFixturePath.fixture")
t.Run("Sub Test", func(t *testing.T) {
require.Equal(t, makeFixturePath(t, ""), "testdata/output/Test_makeFixturePath-Sub_Test.fixture")
})
t.Run("Sub Test With Extra", func(t *testing.T) {
require.Equal(t, makeFixturePath(t, "extra"), "testdata/output/Test_makeFixturePath-Sub_Test_With_Extra-extra.fixture")
})
}
func Test_Fixture(t *testing.T) {
t.Run("bytes", func(t *testing.T) {
Fixture(t, []byte("an array of bytes"))
})
t.Run("string", func(t *testing.T) {
Fixture(t, "a string of text")
})
t.Run("struct", func(t *testing.T) {
Fixture(t, struct {
A string
B int
}{
"something",
1234,
})
})
r := *regen
t.Run("regen", func(t *testing.T) {
b := []byte(fmt.Sprintf("%v", time.Now()))
*regen = true
require.True(t, Regen())
Fixture(t, b)
*regen = false
require.False(t, Regen())
Fixture(t, b)
os.Remove(makeFixturePath(t, ""))
})
*regen = r
}
func Test_InputFixture(t *testing.T) {
input := InputFixture(t, "input.fixture")
require.Equal(t, string(input), "foo")
}
func Test_InputFixtureJson(t *testing.T) {
a := struct {
A string
B string
C int
}{
"aaa", "bbb", 123,
}
b := struct {
A string
B string
C int
}{}
InputFixtureJson(t, "struct.json", &b)
require.Equal(t, a, b)
}