-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfig_test.go
58 lines (45 loc) · 1.3 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
package kinetic
import (
"io/ioutil"
"os/exec"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
const testConfigPath = "kinetic.conf"
func TestBadConfig(t *testing.T) {
Convey("Given an incorrectly formatted config file", t, func() {
moveConfig(t)
Convey("The default configuration should be loaded", func() {
makeBadConfig(t, testConfigPath)
config := getConfig()
So(config.Kinesis.Stream, ShouldNotResemble, nil)
So(config.AWS.AccessKey, ShouldNotResemble, nil)
So(config.AWS.SecretKey, ShouldNotResemble, nil)
restoreConfig(t)
})
})
}
func TestMissingConfig(t *testing.T) {
Convey("Given a missing config file", t, func() {
moveConfig(t)
Convey("The default configuration should be loaded", func() {
config := getConfig()
So(config.Kinesis.Stream, ShouldNotResemble, nil)
So(config.AWS.AccessKey, ShouldNotResemble, nil)
So(config.AWS.SecretKey, ShouldNotResemble, nil)
restoreConfig(t)
})
})
}
func moveConfig(t *testing.T) {
exec.Command("mv", testConfigPath, testConfigPath+".missing").Run()
}
func restoreConfig(t *testing.T) {
exec.Command("mv", testConfigPath+".missing", testConfigPath).Run()
}
func makeBadConfig(t *testing.T, path string) {
err := ioutil.WriteFile(path, []byte("bad=config"), 0644)
if err != nil {
t.Fatalf(err.Error())
}
}