@@ -47,25 +47,25 @@ func (s *ConfigTestSuite) TestNew() {
47
47
expectedCloudConfig CloudConfig
48
48
}{
49
49
{
50
- `
50
+ config : `
51
51
config:
52
52
v1:
53
53
benchmark: cis_k8s
54
54
` ,
55
- "cis_k8s" ,
56
- CloudConfig {},
55
+ expectedType : "cis_k8s" ,
56
+ expectedCloudConfig : CloudConfig {},
57
57
},
58
58
{
59
- `
59
+ config : `
60
60
config:
61
61
v1:
62
62
benchmark: cis_azure
63
63
` ,
64
- "cis_azure" ,
65
- CloudConfig {},
64
+ expectedType : "cis_azure" ,
65
+ expectedCloudConfig : CloudConfig {},
66
66
},
67
67
{
68
- `
68
+ config : `
69
69
config:
70
70
v1:
71
71
benchmark: cis_eks
@@ -79,8 +79,8 @@ config:
79
79
credential_profile_name: credential_profile_name
80
80
role_arn: role_arn
81
81
` ,
82
- "cis_eks" ,
83
- CloudConfig {
82
+ expectedType : "cis_eks" ,
83
+ expectedCloudConfig : CloudConfig {
84
84
Aws : AwsConfig {
85
85
Cred : aws.ConfigAWS {
86
86
AccessKeyID : "key" ,
@@ -229,3 +229,109 @@ revision: 1`,
229
229
})
230
230
}
231
231
}
232
+
233
+ func (s * ConfigTestSuite ) TestCloudConnectorsConfig () {
234
+ tests := map [string ]struct {
235
+ config string
236
+ overwriteEnv func (t * testing.T )
237
+ expectedType string
238
+ expectedCloudConfig CloudConfig
239
+ }{
240
+ "happy path cloud connectors enabled" : {
241
+ config : `
242
+ config:
243
+ v1:
244
+ benchmark: cis_aws
245
+ aws:
246
+ supports_cloud_connectors: true
247
+ credentials:
248
+ external_id: abc123
249
+ ` ,
250
+ expectedType : "cis_aws" ,
251
+ expectedCloudConfig : CloudConfig {
252
+ Aws : AwsConfig {
253
+ CloudConnectors : true ,
254
+ Cred : aws.ConfigAWS {
255
+ ExternalID : "abc123" ,
256
+ },
257
+ CloudConnectorsConfig : CloudConnectorsConfig {},
258
+ },
259
+ },
260
+ },
261
+ "happy path cloud connectors enabled - attempt overwrite roles" : {
262
+ config : `
263
+ config:
264
+ v1:
265
+ benchmark: cis_aws
266
+ aws:
267
+ account_type: single-account
268
+ supports_cloud_connectors: true
269
+ credentials:
270
+ external_id: abc123
271
+ CloudConnectorsConfig:
272
+ LocalRoleARN: "abc123"
273
+ LocalRoleARN: "abc123"
274
+ ` ,
275
+ expectedType : "cis_aws" ,
276
+ expectedCloudConfig : CloudConfig {
277
+ Aws : AwsConfig {
278
+ AccountType : SingleAccount ,
279
+ CloudConnectors : true ,
280
+ Cred : aws.ConfigAWS {
281
+ ExternalID : "abc123" ,
282
+ },
283
+ CloudConnectorsConfig : CloudConnectorsConfig {},
284
+ },
285
+ },
286
+ },
287
+ "happy path cloud connectors enabled - env vars set" : {
288
+ config : `
289
+ config:
290
+ v1:
291
+ benchmark: cis_aws
292
+ aws:
293
+ account_type: single-account
294
+ supports_cloud_connectors: true
295
+ credentials:
296
+ external_id: abc123
297
+ ` ,
298
+ overwriteEnv : func (t * testing.T ) {
299
+ t .Helper ()
300
+ t .Setenv (CloudConnectorsLocalRoleEnvVar , "abc123" )
301
+ t .Setenv (CloudConnectorsGlobalRoleEnvVar , "abc456" )
302
+ t .Setenv (CloudResourceIDEnvVar , "abc789" )
303
+ },
304
+ expectedType : "cis_aws" ,
305
+ expectedCloudConfig : CloudConfig {
306
+ Aws : AwsConfig {
307
+ AccountType : SingleAccount ,
308
+ CloudConnectors : true ,
309
+ Cred : aws.ConfigAWS {
310
+ ExternalID : "abc123" ,
311
+ },
312
+ CloudConnectorsConfig : CloudConnectorsConfig {
313
+ LocalRoleARN : "abc123" ,
314
+ GlobalRoleARN : "abc456" ,
315
+ ResourceID : "abc789" ,
316
+ },
317
+ },
318
+ },
319
+ },
320
+ }
321
+
322
+ for i , test := range tests {
323
+ s .Run (fmt .Sprint (i ), func () {
324
+ if test .overwriteEnv != nil {
325
+ test .overwriteEnv (s .T ())
326
+ }
327
+ cfg , err := config .NewConfigFrom (test .config )
328
+ s .Require ().NoError (err )
329
+
330
+ c , err := New (cfg )
331
+ s .Require ().NoError (err )
332
+
333
+ s .Equal (test .expectedType , c .Benchmark )
334
+ s .Equal (test .expectedCloudConfig , c .CloudConfig )
335
+ })
336
+ }
337
+ }
0 commit comments