-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig_test.go
53 lines (48 loc) · 1.41 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
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGetValidConfig(t *testing.T) {
got, err := getConfig("config.yml.test")
assert.NoError(t, err)
expected := &config{
Pinba: struct {
Addr string `yaml:"host"`
ConnectTimeout time.Duration `yaml:"connect_timeout"`
ReadTimeout time.Duration `yaml:"read_timeout"`
}{
Addr: "pinba-host:5002",
ConnectTimeout: 500 * time.Millisecond,
ReadTimeout: 5 * time.Second,
},
Influxdb: struct {
Addr string `yaml:"addr"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
}{
Addr: "http://influxdb:8086",
User: "username",
Password: "secret",
Database: "pinba-database",
},
Whitelist: struct {
ServerNames []string `yaml:"servers"`
Tags []string `yaml:"tags"`
}{
ServerNames: []string{"example.com", "api.example.com"},
Tags: []string{"server", "region", "script", "status"},
},
}
assert.Equal(t, expected, got)
}
func TestGetConfigFromNotYamlFile(t *testing.T) {
_, err := getConfig("config.go")
assert.EqualError(t, err, "unmarshal failed: yaml: line 38: mapping values are not allowed in this context")
}
func TestGetConfigFromNotExistigFile(t *testing.T) {
_, err := getConfig("no-such-file")
assert.EqualError(t, err, "open no-such-file: no such file or directory")
}