This repository was archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_test.go
More file actions
57 lines (52 loc) · 1.46 KB
/
settings_test.go
File metadata and controls
57 lines (52 loc) · 1.46 KB
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
package main
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"os"
"testing"
)
// TestSettings tests stuff from runtime.go
func TestSettings(t *testing.T) {
Convey("The settings tests, ", t, func() {
chks := []struct {
envvar string
chkFunc interface{}
expPanic bool
}{
{"AWS_ACCESS_KEY_ID", CheckEnvVars, true},
{"LOG_LEVEL", ConfigureLogger, false},
}
for i := range chks {
chk := chks[i]
Convey(fmt.Sprintf("Unsetting %s", chk.envvar), func() {
curVal := os.Getenv(chk.envvar)
os.Unsetenv(chk.envvar)
if chk.expPanic {
So(chk.chkFunc.(func()), ShouldPanic)
} else {
So(chk.chkFunc.(func()), ShouldNotPanic)
}
os.Setenv(chk.envvar, curVal)
})
}
envvar := "LOG_LEVEL"
Convey(fmt.Sprintf("Setting %s to an invalid level", envvar), func() {
curVal := os.Getenv(envvar)
os.Setenv(envvar, "CARROTS")
So(ConfigureLogger, ShouldNotPanic)
os.Setenv(envvar, curVal)
})
envfuncs := map[string]interface{}{"FETCH_OFFSET": FetchOffset, "FETCH_LIMIT": FetchLimit}
for envvar, fun := range envfuncs {
Convey(fmt.Sprintf("Setting %s to -2", envvar), func() {
curVal := os.Getenv(envvar)
os.Setenv(envvar, "-2")
So(func() { fun.(func() int)() }, ShouldPanic)
os.Setenv(envvar, curVal)
})
}
Convey("intFromEnvVar returns the default value if envvar does not exist", func() {
So(intFromEnvVar("SOME_VALUE_THAT_DOES_NOT_EXISTS", 19), ShouldEqual, 19)
})
})
}