-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
105 lines (83 loc) · 2.23 KB
/
config_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package gouse
import "testing"
func TestReadJSON(t *testing.T) {
type Meta struct {
Lang string `json:"lang"`
Type string `json:"type"`
}
type configuration struct {
Host string `json:"host"`
Port int `json:"port"`
Meta Meta `json:"meta"`
}
var conf configuration
if err := ReadJSON("./mockdata/config.json", &conf); err != nil {
t.Fatal(err)
}
if conf.Host != "localhost" {
t.Fatalf("expected host to be 'localhost', got %q", conf.Host)
}
if conf.Port != 8080 {
t.Fatalf("expected port to be 8080, got %d", conf.Port)
}
if conf.Meta.Lang != "golang" {
t.Fatalf("expected meta.lang to be 'golang', got %q", conf.Meta.Lang)
}
if conf.Meta.Type != "package" {
t.Fatalf("expected meta.type to be 'package', got %q", conf.Meta.Type)
}
}
func TestReadTOML(t *testing.T) {
type Meta struct {
Lang string `toml:"lang"`
Type string `toml:"type"`
}
type configuration struct {
Host string `toml:"host"`
Port int `toml:"port"`
Meta Meta `toml:"meta"`
}
var conf configuration
if err := ReadTOML("./mockdata/config.toml", &conf); err != nil {
t.Fatal(err)
}
if conf.Host != "localhost" {
t.Fatalf("expected host to be 'localhost', got %q", conf.Host)
}
if conf.Port != 8080 {
t.Fatalf("expected port to be 8080, got %d", conf.Port)
}
if conf.Meta.Lang != "golang" {
t.Fatalf("expected meta.lang to be 'golang', got %q", conf.Meta.Lang)
}
if conf.Meta.Type != "package" {
t.Fatalf("expected meta.type to be 'package', got %q", conf.Meta.Type)
}
}
func TestReadYAML(t *testing.T) {
type Meta struct {
Lang string `yaml:"lang"`
Type string `yaml:"type"`
}
type Configuration struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Meta Meta `yaml:"meta"`
}
var conf Configuration
if err := ReadYAML("./mockdata/config.yaml", &conf); err != nil {
t.Fatal(err)
}
if conf.Host != "localhost" {
t.Fatalf("expected host to be 'localhost', got %q", conf.Host)
}
if conf.Port != 8080 {
t.Fatalf("expected port to be 8080, got %d", conf.Port)
}
if conf.Meta.Lang != "golang" {
t.Fatalf("expected meta.lang to be 'golang', got %q", conf.Meta.Lang)
}
if conf.Meta.Type != "package" {
t.Fatalf("expected meta.type to be 'package', got %q", conf.Meta.Type)
}
}