@@ -68,17 +68,17 @@ func makeConfigMapSource(descriptor sourceReference) *coreV1.EnvVarSource {
6868 }
6969}
7070
71- func (s * EnVarValueFromTestSuite ) addContainerWithEnvFromSecret (envRef envReference ) { // Fix: Remove name parameter
71+ func (s * EnVarValueFromTestSuite ) addContainerWithEnvFromSecret (envRef envReference ) {
7272 var valueFrom * coreV1.EnvVarSource
7373 switch envRef .Kind {
7474 case "secret" :
7575 valueFrom = makeSecretSource (envRef .Source )
7676 case "configmap" :
7777 valueFrom = makeConfigMapSource (envRef .Source )
7878 default :
79- s .Require ().FailNow (fmt .Sprintf ("Unknown source kind %s" , envRef .Kind )) // Fix: Use s.Require().FailNow
79+ s .Require ().FailNow (fmt .Sprintf ("Unknown source kind %s" , envRef .Kind ))
8080 }
81- s .ctx .AddContainerToDeployment (s .T (), targetDeploymentName , coreV1.Container { // Fix: Hardcode targetDeploymentName
81+ s .ctx .AddContainerToDeployment (s .T (), targetDeploymentName , coreV1.Container {
8282 Name : "container" ,
8383 Env : []coreV1.EnvVar {
8484 {
@@ -342,3 +342,86 @@ func (s *EnVarValueFromTestSuite) TestKeysEmptyMap() {
342342 keys := Keys (emptyMap )
343343 s .Empty (keys )
344344}
345+
346+ func (s * EnVarValueFromTestSuite ) TestExtractRegexListInvalidConfigMaps () {
347+ p := params.Params {IgnoredConfigMaps : []string {"[invalid(" }}
348+ _ , err := extractRegexList (p .IgnoredConfigMaps )
349+ s .Error (err )
350+ s .Contains (err .Error (), "invalid regex [invalid(" )
351+ }
352+
353+ func (s * EnVarValueFromTestSuite ) TestUnknownKeyInSecretWithStringData () {
354+ s .ctx .AddMockDeployment (s .T (), targetDeploymentName )
355+ secret := & coreV1.Secret {
356+ ObjectMeta : metav1.ObjectMeta {Name : "test-secret" },
357+ StringData : map [string ]string {"key1" : "value" },
358+ }
359+ s .ctx .AddObject ("test-secret" , secret )
360+ s .addContainerWithEnvFromSecret (envReference {
361+ Name : "my-secret" ,
362+ Kind : "secret" ,
363+ Source : sourceReference {
364+ Name : "test-secret" ,
365+ Key : "unknown-key" ,
366+ Optional : pointers .Bool (false ),
367+ },
368+ })
369+ s .Validate (s .ctx , []templates.TestCase {
370+ {
371+ Param : params.Params {},
372+ Diagnostics : map [string ][]diagnostic.Diagnostic {
373+ targetDeploymentName : {{
374+ Message : "The container \" container\" is referring to an unknown key \" unknown-key\" in secret \" test-secret\" " ,
375+ }},
376+ },
377+ },
378+ })
379+ }
380+
381+ func (s * EnVarValueFromTestSuite ) TestMultipleIgnoredSecrets () {
382+ s .ctx .AddMockDeployment (s .T (), targetDeploymentName )
383+ secret1 := & coreV1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "secret1" }, Data : map [string ][]byte {"key" : []byte ("value" )}}
384+ secret2 := & coreV1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "secret2" }, Data : map [string ][]byte {"key" : []byte ("value" )}}
385+ s .ctx .AddObject ("secret1" , secret1 )
386+ s .ctx .AddObject ("secret2" , secret2 )
387+ s .addContainerWithEnvFromSecret (envReference {
388+ Name : "my-secret" ,
389+ Kind : "secret" ,
390+ Source : sourceReference {
391+ Name : "secret1" ,
392+ Key : "key" ,
393+ Optional : pointers .Bool (false ),
394+ },
395+ })
396+ s .Validate (s .ctx , []templates.TestCase {
397+ {
398+ Param : params.Params {IgnoredSecrets : []string {"^secret2$" }},
399+ Diagnostics : map [string ][]diagnostic.Diagnostic {
400+ targetDeploymentName : {},
401+ },
402+ },
403+ })
404+ }
405+
406+ func (s * EnVarValueFromTestSuite ) TestEmptyObjectList () {
407+ s .ctx .AddMockDeployment (s .T (), targetDeploymentName )
408+ s .addContainerWithEnvFromSecret (envReference {
409+ Name : "my-secret" ,
410+ Kind : "secret" ,
411+ Source : sourceReference {
412+ Name : "test-secret" ,
413+ Key : "key" ,
414+ Optional : pointers .Bool (false ),
415+ },
416+ })
417+ s .Validate (s .ctx , []templates.TestCase {
418+ {
419+ Param : params.Params {},
420+ Diagnostics : map [string ][]diagnostic.Diagnostic {
421+ targetDeploymentName : {{
422+ Message : "The container \" container\" is referring to an unknown secret \" test-secret\" " ,
423+ }},
424+ },
425+ },
426+ })
427+ }
0 commit comments