-
Notifications
You must be signed in to change notification settings - Fork 0
/
ayaml_test.go
77 lines (61 loc) · 1.74 KB
/
ayaml_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
package ayaml
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
const validYaml = "./test_fixture/a.yml"
func TestAyamlNew(t *testing.T) {
_, err := New("fileNotExists")
require.Error(t, err)
a, err := New("./test_fixture/invalid.yml")
require.Error(t, err)
a, err = New(validYaml)
require.NoError(t, err)
fd := a.fileData
assert.Equal(t, 100000000, fd["valid_user"]["id"])
assert.Equal(t, "Taro", fd["valid_user"]["name"])
assert.Equal(t, "2014-01-01T00:00:00Z", fd["valid_user"]["created"])
}
func TestSchema(t *testing.T) {
a, _ := New(validYaml)
a.Schema("valid_user")
assert.Equal(t, "valid_user", a.schema)
}
func TestWith(t *testing.T) {
a, _ := New(validYaml)
a.Schema("valid_user").With(SchemaData{
"id": 1,
"name": "Jiro",
"created": "2015-01-01T00:00:00Z",
})
fd := a.fileData
assert.Equal(t, 1, fd["valid_user"]["id"])
assert.Equal(t, "Jiro", fd["valid_user"]["name"])
assert.Equal(t, "2015-01-01T00:00:00Z", fd["valid_user"]["created"])
}
func TestDump(t *testing.T) {
a, _ := New(validYaml)
_, err := a.Dump()
require.Error(t, err)
_, err = a.Schema("invalid schema").Dump()
require.Error(t, err)
d, err := a.Schema("valid_user").Dump()
require.NoError(t, err)
assert.Equal(t, 100000000, d["id"])
assert.Equal(t, "Taro", d["name"])
assert.Equal(t, "2014-01-01T00:00:00Z", d["created"])
}
func TestWithDump(t *testing.T) {
a, _ := New(validYaml)
_, err := a.WithDump(SchemaData{})
require.Error(t, err)
d, err := a.Schema("valid_user").WithDump(SchemaData{"id": 1})
require.NoError(t, err)
assert.Equal(t, 1, d["id"])
}
func TestSeq(t *testing.T) {
a, _ := New(validYaml)
seq := Seq(a)
assert.Equal(t, 100000000, seq.Base.fileData["valid_user"]["id"])
}