@@ -651,4 +651,49 @@ func Test_GetDeploymentConfig(t *testing.T) {
651651 result := cfg .GetDeploymentConfig ()
652652 require .Nil (t , result )
653653 })
654+
655+ // Test that returned map is a defensive copy (mutations don't affect original)
656+ t .Run ("returned map is defensive copy - mutations don't affect original" , func (t * testing.T ) {
657+ rawConfig := []byte (`{
658+ "deploymentConfig": {
659+ "nodeSelector": {
660+ "kubernetes.io/os": "linux"
661+ }
662+ }
663+ }` )
664+
665+ schema , err := bundle .GetConfigSchema ()
666+ require .NoError (t , err )
667+
668+ cfg , err := config .UnmarshalConfig (rawConfig , schema , "" )
669+ require .NoError (t , err )
670+
671+ // Get the deploymentConfig
672+ result1 := cfg .GetDeploymentConfig ()
673+ require .NotNil (t , result1 )
674+
675+ // Mutate the returned map
676+ result1 ["nodeSelector" ] = map [string ]any {
677+ "mutated" : "value" ,
678+ }
679+ result1 ["newField" ] = "added"
680+
681+ // Get deploymentConfig again - should be unaffected by mutations
682+ result2 := cfg .GetDeploymentConfig ()
683+ require .NotNil (t , result2 )
684+
685+ // Original values should be intact
686+ require .Equal (t , map [string ]any {
687+ "nodeSelector" : map [string ]any {
688+ "kubernetes.io/os" : "linux" ,
689+ },
690+ }, result2 )
691+
692+ // New field should not exist
693+ _ , exists := result2 ["newField" ]
694+ require .False (t , exists )
695+
696+ // result1 should have the mutations
697+ require .Equal (t , "added" , result1 ["newField" ])
698+ })
654699}
0 commit comments