-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
50 lines (41 loc) · 964 Bytes
/
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
package main
import (
"strings"
"testing"
)
func TestParseConf(t *testing.T) {
yml := `# Server configuration
server:
host: "localhost"
port: 9990
weather_api_key: "put_your_key_here"
`
r := strings.NewReader(yml)
config, err := ParseConf(r)
if err != nil {
t.Errorf("got err = %v", err)
}
if config.Server.Host != "localhost" {
t.Errorf("got config.Server.Host = %s; want %s", config.Server.Host, "localhost")
}
if config.Server.Port != "9990" {
t.Errorf("got config.Server.Port = %s; want %s", config.Server.Port, "9990")
}
if config.WeatherAPIKey != "put_your_key_here" {
t.Errorf("got config.WeatherAPIKey = %s; want %s", config.Server.Host, "put_your_key_here")
}
}
func TestInvalidYaml(t *testing.T) {
yml := `# Server configuration
server:
host: "localhost"
port: 9990
oops
weather_api_key: "put_your_key_here"
`
r := strings.NewReader(yml)
_, err := ParseConf(r)
if err == nil {
t.Errorf("got err = nil")
}
}