-
Notifications
You must be signed in to change notification settings - Fork 64
/
file_test.go
91 lines (72 loc) · 1.48 KB
/
file_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
85
86
87
88
89
90
91
package multiconfig
import (
"os"
"testing"
)
func TestYAML(t *testing.T) {
m := NewWithPath(testYAML)
s := &Server{}
if err := m.Load(s); err != nil {
t.Error(err)
}
testStruct(t, s, getDefaultServer())
}
func TestYAML_Reader(t *testing.T) {
f, err := os.Open(testYAML)
if err != nil {
t.Fatal(err)
}
defer f.Close()
l := MultiLoader(&TagLoader{}, &YAMLLoader{Reader: f})
s := &Server{}
if err := l.Load(s); err != nil {
t.Error(err)
}
testStruct(t, s, getDefaultServer())
}
func TestToml(t *testing.T) {
m := NewWithPath(testTOML)
s := &Server{}
if err := m.Load(s); err != nil {
t.Error(err)
}
testStruct(t, s, getDefaultServer())
}
func TestToml_Reader(t *testing.T) {
f, err := os.Open(testTOML)
if err != nil {
t.Fatal(err)
}
defer f.Close()
l := MultiLoader(&TagLoader{}, &TOMLLoader{Reader: f})
s := &Server{}
if err := l.Load(s); err != nil {
t.Error(err)
}
testStruct(t, s, getDefaultServer())
}
func TestJSON(t *testing.T) {
m := NewWithPath(testJSON)
s := &Server{}
if err := m.Load(s); err != nil {
t.Error(err)
}
testStruct(t, s, getDefaultServer())
}
func TestJSON_Reader(t *testing.T) {
f, err := os.Open(testJSON)
if err != nil {
t.Fatal(err)
}
defer f.Close()
l := MultiLoader(&TagLoader{}, &JSONLoader{Reader: f})
s := &Server{}
if err := l.Load(s); err != nil {
t.Error(err)
}
testStruct(t, s, getDefaultServer())
}
// func TestJSON2(t *testing.T) {
// ExampleEnvironmentLoader()
// ExampleTOMLLoader()
// }