forked from Nomon/gonfig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv_test.go
62 lines (59 loc) · 1.71 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
package unicon_test
import (
"os"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/taybin/unicon"
)
var _ = Describe("EnvConfig", func() {
var (
err error
cfg ReadableConfig
)
BeforeEach(func() {
cfg = NewEnvConfig("")
err = cfg.Load()
Expect(err).ToNot(HaveOccurred())
})
It("Should load variables from environment", func() {
Expect(len(cfg.All()) > 0).To(BeTrue())
env := os.Environ()
Expect(len(env) > 0).To(BeTrue())
for _, kvpair := range env {
pairs := strings.Split(kvpair, "=")
Expect(len(pairs) >= 2).To(BeTrue())
Expect(cfg.Get(strings.ToLower(pairs[0]))).To(Equal(pairs[1]))
}
})
It("Should create namespaces if provided, split by _", func() {
os.Setenv("POSTGRES_HOST", "localhost")
cfg = NewEnvConfig("", "postgres")
cfg.Load()
Expect(cfg.Get("postgres.host")).To(Equal("localhost"))
})
It("Should create namespaces if provided in UPPERCASE", func() {
os.Setenv("POSTGRES_HOST", "localhost")
cfg = NewEnvConfig("", "POSTGRES")
cfg.Load()
Expect(cfg.Get("postgres.host")).To(Equal("localhost"))
})
It("Should not create namespaces if not provided", func() {
os.Setenv("POSTGRES_HOST", "localhost")
cfg = NewEnvConfig("")
cfg.Load()
Expect(cfg.Get("postgres_host")).To(Equal("localhost"))
})
It("Should create namespaces if provided, split by -", func() {
os.Setenv("POSTGRES-HOST", "localhost")
cfg = NewEnvConfig("", "postgres")
cfg.Load()
Expect(cfg.Get("postgres.host")).To(Equal("localhost"))
})
It("Should create namespaces if provided, split by :", func() {
os.Setenv("POSTGRES:HOST", "localhost")
cfg = NewEnvConfig("", "postgres")
cfg.Load()
Expect(cfg.Get("postgres.host")).To(Equal("localhost"))
})
})