@@ -25,7 +25,7 @@ func TestValidConfigLoad(t *testing.T) {
25
25
output-path: "/nothome"
26
26
`
27
27
28
- loadedConfig , err := ParseConfig ([]byte (configFileContents ))
28
+ loadedConfig , err := ParseConfig ([]byte (configFileContents ), false )
29
29
if err != nil {
30
30
t .Fatalf ("unexpected error: %v" , err )
31
31
}
@@ -68,7 +68,7 @@ func TestValidConfigWithEndpointLoad(t *testing.T) {
68
68
always-fail: false
69
69
`
70
70
71
- loadedConfig , err := ParseConfig ([]byte (configFileContents ))
71
+ loadedConfig , err := ParseConfig ([]byte (configFileContents ), false )
72
72
if err != nil {
73
73
t .Errorf ("unexpected error: %v" , err )
74
74
}
@@ -114,7 +114,7 @@ func TestValidVenafiCloudConfigLoad(t *testing.T) {
114
114
upload_path: "/testing/path"
115
115
`
116
116
117
- loadedConfig , err := ParseConfig ([]byte (configFileContents ))
117
+ loadedConfig , err := ParseConfig ([]byte (configFileContents ), false )
118
118
if err != nil {
119
119
t .Fatalf ("unexpected error: %v" , err )
120
120
}
@@ -149,7 +149,7 @@ func TestValidVenafiCloudConfigLoad(t *testing.T) {
149
149
func TestInvalidConfigError (t * testing.T ) {
150
150
configFileContents := `data-gatherers: "things"`
151
151
152
- _ , parseError := ParseConfig ([]byte (configFileContents ))
152
+ _ , parseError := ParseConfig ([]byte (configFileContents ), false )
153
153
154
154
expectedError := fmt .Errorf ("yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `things` into []agent.DataGatherer" )
155
155
@@ -159,26 +159,35 @@ func TestInvalidConfigError(t *testing.T) {
159
159
}
160
160
161
161
func TestMissingConfigError (t * testing.T ) {
162
- _ , parseError := ParseConfig ([]byte ("" ))
163
-
164
- if parseError == nil {
165
- t .Fatalf ("expected error, got nil" )
166
- }
167
-
168
- expectedErrorLines := []string {
169
- "2 errors occurred:" ,
170
- "\t * organization_id is required" ,
171
- "\t * cluster_id is required" ,
172
- "\n " ,
173
- }
174
-
175
- expectedError := strings .Join (expectedErrorLines , "\n " )
176
-
177
- gotError := parseError .Error ()
178
-
179
- if gotError != expectedError {
180
- t .Errorf ("\n got=\n %v\n want=\n %s\n diff=\n %s" , gotError , expectedError , diff .Diff (gotError , expectedError ))
181
- }
162
+ t .Run ("fail to parse config if organization_id or cluster_id are missing (venafi-cloud not enabled)" , func (t * testing.T ) {
163
+ _ , parseError := ParseConfig ([]byte ("" ), false )
164
+
165
+ if parseError == nil {
166
+ t .Fatalf ("expected error, got nil" )
167
+ }
168
+
169
+ expectedErrorLines := []string {
170
+ "2 errors occurred:" ,
171
+ "\t * organization_id is required" ,
172
+ "\t * cluster_id is required" ,
173
+ "\n " ,
174
+ }
175
+
176
+ expectedError := strings .Join (expectedErrorLines , "\n " )
177
+
178
+ gotError := parseError .Error ()
179
+
180
+ if gotError != expectedError {
181
+ t .Errorf ("\n got=\n %v\n want=\n %s\n diff=\n %s" , gotError , expectedError , diff .Diff (gotError , expectedError ))
182
+ }
183
+ })
184
+ t .Run ("successfully parse config if organization_id or cluster_id are missing (venafi-cloud is enabled)" , func (t * testing.T ) {
185
+ _ , parseError := ParseConfig ([]byte ("" ), true )
186
+
187
+ if parseError != nil {
188
+ t .Fatalf ("unxexpected error, no error should have occured when parsing configuration: %s" , parseError )
189
+ }
190
+ })
182
191
}
183
192
184
193
func TestPartialMissingConfigError (t * testing.T ) {
@@ -190,7 +199,7 @@ func TestPartialMissingConfigError(t *testing.T) {
190
199
organization_id: "example"
191
200
cluster_id: "example-cluster"
192
201
data-gatherers:
193
- - kind: dummy` ))
202
+ - kind: dummy` ), false )
194
203
195
204
if parseError == nil {
196
205
t .Fatalf ("expected error, got nil" )
@@ -218,7 +227,7 @@ func TestInvalidServerError(t *testing.T) {
218
227
cluster_id: "my_cluster"
219
228
data-gatherers:
220
229
- kind: dummy
221
- name: dummy` ))
230
+ name: dummy` ), false )
222
231
223
232
if parseError == nil {
224
233
t .Fatalf ("expected error, got nil" )
@@ -246,7 +255,7 @@ func TestInvalidDataGathered(t *testing.T) {
246
255
path: /api/v1/data
247
256
schedule: "* * * * *"
248
257
data-gatherers:
249
- - kind: "foo"` ))
258
+ - kind: "foo"` ), false )
250
259
251
260
if parseError == nil {
252
261
t .Fatalf ("expected error, got nil" )
0 commit comments