@@ -7,7 +7,55 @@ import (
77 . "github.com/onsi/gomega"
88)
99
10- var _ = Describe ("Config" , func () {
10+ var _ = Describe ("LoadConfig" , func () {
11+ var (
12+ configFilePath string
13+ config * Config
14+ err error
15+ )
16+ const (
17+ quickStartConfigPath = "../../../examples/quickstart.yaml"
18+ invalidConfigPath = "not_exist.yaml"
19+ )
20+
21+ JustBeforeEach (func () {
22+ config , err = NewManager (configFilePath ).LoadConfig ()
23+ })
24+
25+ Context ("when config file is valid" , func () {
26+ BeforeEach (func () {
27+ configFilePath = quickStartConfigPath
28+ })
29+
30+ Specify ("the error should be nil" , func () {
31+ Expect (config ).NotTo (BeNil ())
32+ Expect (err ).To (BeNil ())
33+ })
34+ It ("should state filed correctly" , func () {
35+ Expect (config .State .Backend ).To (Or (Equal ("local" ), Equal ("s3" )))
36+ Expect (config .State .Options .StateFile ).To (Equal ("devstream.state" ))
37+ })
38+ Specify ("Tools Options cannot be empty" , func () {
39+ Expect (len (config .Tools )).Should (BeNumerically (">" , 0 ))
40+ Expect (config .Tools [0 ].Name ).ShouldNot (BeEmpty ())
41+ Expect (config .Tools [0 ].InstanceID ).ShouldNot (BeEmpty ())
42+ Expect (config .Tools [0 ].Options ).ShouldNot (BeEmpty ())
43+ Expect (len (config .Tools [0 ].DependsOn )).ShouldNot (BeNil ())
44+ })
45+ })
46+
47+ Context ("when config file is invalid" , func () {
48+ BeforeEach (func () {
49+ configFilePath = invalidConfigPath
50+ })
51+ It ("should error" , func () {
52+ Expect (err ).To (HaveOccurred ())
53+ Expect (config ).To (BeNil ())
54+ })
55+ })
56+ })
57+
58+ var _ = Describe ("config renders" , func () {
1159 var (
1260 emptyVariable []byte
1361 validToolBytes []byte
@@ -38,30 +86,9 @@ state:
3886 options:
3987 stateFile: devstream.state` )
4088 })
41- Describe ("LoadConfig yaml" , func () {
42- configStateObj , err := NewManager ("../../../examples/quickstart.yaml" ).LoadConfig ()
43- Context ("when the Yaml parses successfully" , func () {
44- It ("should state filed correctly" , func () {
45- Expect (configStateObj .State .Backend ).To (Or (Equal ("local" ), Equal ("s3" )))
46- Expect (configStateObj .State .Options .StateFile ).To (Equal ("devstream.state" ))
47- })
48- Specify ("Tools Options cannot be empty" , func () {
49- Expect (len (configStateObj .Tools )).ShouldNot (BeNil ())
50- Expect (configStateObj .Tools [0 ].Name ).ShouldNot (BeEmpty ())
51- Expect (configStateObj .Tools [0 ].InstanceID ).ShouldNot (BeEmpty ())
52- Expect (configStateObj .Tools [0 ].Options ).ShouldNot (BeEmpty ())
53- Expect (len (configStateObj .Tools [0 ].DependsOn )).ShouldNot (BeNil ())
54- })
55- })
56- Context ("when the Yaml parses fails" , func () {
57- It ("should not error" , func () {
58- Expect (err ).NotTo (HaveOccurred ())
59- })
60- })
61- })
6289
6390 Describe ("renderConfigs func" , func () {
64- Context ( "when config wrong" , func () {
91+ When ( " config is wrong" , func () {
6592 It ("should return error if data is not valid yaml string" , func () {
6693 notValidStr := "this is not valid yaml"
6794 notValidBytes := []byte (notValidStr )
@@ -78,7 +105,7 @@ state:
78105
79106 })
80107
81- Context ( "when config all valid" , func () {
108+ When ( " config is valid" , func () {
82109 It ("should generate config" , func () {
83110 config , err := NewManager ("" ).renderConfigs (validCoreBytes , emptyVariable , validToolBytes )
84111 Expect (err ).Error ().ShouldNot (HaveOccurred ())
@@ -88,7 +115,7 @@ state:
88115 })
89116
90117 Describe ("renderToolsFromCoreConfigAndConfigBytes func" , func () {
91- Context ( "when config error" , func () {
118+ When ( " config error" , func () {
92119 It ("should return error if tool file is empty and tools config file is empty" , func () {
93120 config := CoreConfig {}
94121 tools , err := NewManager ("" ).renderToolsFromCoreConfigAndConfigBytes (& config , emptyVariable , emptyVariable )
@@ -98,7 +125,7 @@ state:
98125
99126 })
100127 })
101- Context ( "when tool config valid" , func () {
128+ When ( " tool config valid" , func () {
102129 It ("should generate tools array" , func () {
103130 config := CoreConfig {}
104131 tools , err := NewManager ("" ).renderToolsFromCoreConfigAndConfigBytes (& config , validToolBytes , emptyVariable )
@@ -109,7 +136,7 @@ state:
109136 })
110137
111138 Describe ("loadOriginalConfigFile func" , func () {
112- Context ( "when file name error" , func () {
139+ When ( " file name error" , func () {
113140 It ("should return error" , func () {
114141 errorFileName := "error_file_name.yaml"
115142 _ , err := NewManager (errorFileName ).loadOriginalConfigFile ()
@@ -119,7 +146,7 @@ state:
119146 })
120147
121148 Describe ("splitConfigFileBytes func" , func () {
122- Context ( "when input text not valid" , func () {
149+ When ( " input text not valid" , func () {
123150 It ("should return error if fomat not valid" , func () {
124151 notValidContent := []byte (`
125152 ---
@@ -145,7 +172,7 @@ tools:
145172 Expect (err .Error ()).Should (ContainSubstring ("multiple sections" ))
146173 })
147174 })
148- Context ( "when input text is valid" , func () {
175+ When ( " input text is valid" , func () {
149176
150177 It ("should return config bytes" , func () {
151178 validArray := [][]byte {
@@ -164,7 +191,7 @@ tools:
164191 })
165192
166193 Describe ("checkConfigType func" , func () {
167- Context ( "when input not valid " , func () {
194+ When ( " input is invalid " , func () {
168195 It ("should return false if config type not valid" , func () {
169196 notValidType := []byte (`
170197test:
@@ -183,7 +210,7 @@ test:
183210 Expect (isValid ).Should (BeFalse ())
184211 })
185212 })
186- Context ( "when input is right" , func () {
213+ When ( " input is right" , func () {
187214 It ("should return true and error is nil" , func () {
188215 isValid , err := NewManager ("" ).checkConfigType (validCoreBytes , "core" )
189216 Expect (err ).Error ().ShouldNot (HaveOccurred ())
0 commit comments