-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
46 lines (40 loc) · 935 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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadConfig(t *testing.T) {
conf := AppConfig{
ProxyOps: []ProxySettings{
ProxySettings{
Src: "dummy-source-1",
Dest: []string{"dummy-destination-1", "dummy-destination-2"},
Interval: 20,
},
ProxySettings{
Src: "dummy-source-2",
Dest: []string{"dummy-destination-3", "dummy-destination-4"},
Interval: 40,
},
},
}
b, _ := json.Marshal(&conf)
fname := "/tmp/dummy-config.json"
ioutil.WriteFile(fname, b, 0644)
defer os.Remove(fname)
c, err := LoadConfig(fname)
assert.NoError(t, err)
assert.Equal(t, conf.ProxyOps, c.ProxyOps)
}
func TestLoadConfigError(t *testing.T) {
_, err := LoadConfig("non-existing.json")
assert.Error(t, err)
}
func TestPretty(t *testing.T) {
conf := AppConfig{}
pretty := conf.Pretty()
assert.IsType(t, "", pretty)
}