forked from kdar/factorcfg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_test.go
72 lines (58 loc) · 1.62 KB
/
env_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package factorcfg
import (
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func setupEnv() {
os.Setenv("FACTORCFG_A", "hey===stuff=things=")
os.Setenv("FACTORCFG_B", "5")
os.Setenv("FACTORCFG_C", "1.6")
os.Setenv("FACTORCFG_D", "hey,there,guy")
os.Setenv("FACTORCFG_E", "true")
os.Setenv("FACTORCFG_NESTED_A", "there")
os.Setenv("FACTORCFG_NESTED_B", "4")
}
func TestEnv(t *testing.T) {
setupEnv()
Convey("Given a loader using Env", t, func() {
loader := NewLoader()
loader.Use(NewEnv())
Convey("We should find the environment in our spec", func() {
spec := &cfgTest{}
err := loader.Load(spec)
So(err, ShouldBeNil)
So(spec, ShouldResemble, cfgExample)
})
})
}
// var (
// envTplTest = `{{ range $_, $v := . }}{{index $v.Tags "env"}}={{$v.String}} ({{$v.Type}})
// {{index $v.Tags "doc"}}
// {{ end }}`
// envTplResult = []byte(`FACTORCFG_A="hey" (string)
// doc of A
// FACTORCFG_B=5 (int)
// FACTORCFG_C=1.6 (float32)
// FACTORCFG_D=[]string{"hey", "there", "guy"} ([]string)
// FACTORCFG_E=true (bool)
// FACTORCFG_NESTED_A="there" (string)
// FACTORCFG_NESTED_B=4 (int)
// doc of Nested.B
// `)
// )
// func TestEnvRender(t *testing.T) {
// setupEnv()
// Convey("Given a loader using Env", t, func() {
// loader := NewLoader()
// loader.Use(NewEnv())
// Convey("We should render our spec correctly", func() {
// tmpl, err := template.New("spec").Parse(envTplTest)
// So(tmpl, ShouldNotBeNil)
// So(err, ShouldBeNil)
// data, err := Render(cfgExample, tmpl)
// So(err, ShouldBeNil)
// So(string(data), ShouldEqual, string(envTplResult))
// })
// })
// }