-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_test.go
73 lines (58 loc) · 1.64 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main_test
import (
cfcommon "github.com/govau/cf-common"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/AusDTO/pe-rds-broker"
"io/ioutil"
"github.com/AusDTO/pe-rds-broker/rdsbroker"
"gopkg.in/yaml.v2"
)
var _ = Describe("Config", func() {
var (
config Config
validConfig = Config{
LogLevel: "DEBUG",
RDSConfig: rdsbroker.Config{
Region: "rds-region",
DBPrefix: "cf",
},
}
)
Describe("Validate", func() {
BeforeEach(func() {
config = validConfig
})
It("does not return error if all sections are valid", func() {
err := config.Validate()
Expect(err).ToNot(HaveOccurred())
})
It("returns error if LogLevel is not valid", func() {
config.LogLevel = ""
err := config.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Must provide a non-empty LogLevel"))
})
It("returns error if RDS configuration is not valid", func() {
config.RDSConfig = rdsbroker.Config{}
err := config.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Validating RDS configuration"))
})
})
Describe("LoadConfig", func() {
var (
configFile = "config-sample.yml"
)
It("parses sample config", func() {
Expect(LoadConfig(cfcommon.NewDefaultEnvLookup(), configFile)).NotTo(BeZero())
})
It("parses all information in sample config", func() {
config, err := LoadConfig(cfcommon.NewDefaultEnvLookup(), configFile)
Expect(err).NotTo(HaveOccurred())
configStr, err := ioutil.ReadFile(configFile)
Expect(err).NotTo(HaveOccurred())
Expect(yaml.Marshal(config)).To(MatchYAML(configStr))
})
})
})