-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
45 lines (38 loc) · 1.22 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
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadConfig(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
assert.FailNow(t, "Can't get cwd")
}
filename, err := filepath.Abs(filepath.Join(cwd, "fixtures/config1.toml"))
if err != nil {
assert.FailNow(t, "Can't get absolute path of config fixture")
}
config, err := loadConfig(filename)
assert.Nil(t, err, "Error occured: %v", err)
assert.Equal(t, "10.0.0.1:1012", config.Callmonitor.Host, "Invalid call monitor host")
assert.Equal(t, "UTC", config.Callmonitor.Timezone, "Invalid timezone")
assert.Equal(t, "10.0.0.223", config.Redis.Host, "Invalid redis host")
assert.Equal(t, "call", config.Redis.Topic, "Invalid redis topic")
}
func TestLoadConfigErrors(t *testing.T) {
var err error
_, err = loadConfig("fixtures/doesnotexist.toml")
assert.Error(t, err, "Accepted invalid filename")
cwd, err := os.Getwd()
if err != nil {
assert.FailNow(t, "Can't get cwd")
}
filename, err := filepath.Abs(filepath.Join(cwd, "fixtures/configInvalid.toml"))
if err != nil {
assert.FailNow(t, "Can't get absolute path of config fixture")
}
_, err = loadConfig(filename)
assert.Error(t, err, "Accepted invalid toml")
}