55 "testing"
66
77 "github.com/stretchr/testify/require"
8+ corev1 "k8s.io/api/core/v1"
9+ "k8s.io/apimachinery/pkg/api/resource"
810 "k8s.io/utils/ptr"
911
1012 "github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -596,7 +598,7 @@ func Test_GetDeploymentConfig(t *testing.T) {
596598 tests := []struct {
597599 name string
598600 rawConfig []byte
599- expectedDeploymentConfig map [ string ] any
601+ expectedDeploymentConfig * config. DeploymentConfig
600602 expectedDeploymentConfigNil bool
601603 }{
602604 {
@@ -628,13 +630,13 @@ func Test_GetDeploymentConfig(t *testing.T) {
628630 }
629631 }
630632 }` ),
631- expectedDeploymentConfig : map [ string ] any {
632- "nodeSelector" : map [string ]any {
633+ expectedDeploymentConfig : & config. DeploymentConfig {
634+ NodeSelector : map [string ]string {
633635 "kubernetes.io/os" : "linux" ,
634636 },
635- "resources" : map [ string ] any {
636- "requests" : map [ string ] any {
637- "memory" : "128Mi" ,
637+ Resources : & corev1. ResourceRequirements {
638+ Requests : corev1. ResourceList {
639+ corev1 . ResourceMemory : resource . MustParse ( "128Mi" ) ,
638640 },
639641 },
640642 },
@@ -650,7 +652,8 @@ func Test_GetDeploymentConfig(t *testing.T) {
650652 cfg , err := config .UnmarshalConfig (tt .rawConfig , schema , "" )
651653 require .NoError (t , err )
652654
653- result := cfg .GetDeploymentConfig ()
655+ result , err := cfg .GetDeploymentConfig ()
656+ require .NoError (t , err )
654657 if tt .expectedDeploymentConfigNil {
655658 require .Nil (t , result )
656659 } else {
@@ -663,12 +666,13 @@ func Test_GetDeploymentConfig(t *testing.T) {
663666 // Test nil config separately
664667 t .Run ("nil config returns nil" , func (t * testing.T ) {
665668 var cfg * config.Config
666- result := cfg .GetDeploymentConfig ()
669+ result , err := cfg .GetDeploymentConfig ()
670+ require .NoError (t , err )
667671 require .Nil (t , result )
668672 })
669673
670- // Test that returned map is a defensive copy (mutations don't affect original)
671- t .Run ("returned map is defensive copy - mutations don't affect original" , func (t * testing.T ) {
674+ // Test that returned struct is a separate instance (mutations don't affect original)
675+ t .Run ("returned struct is independent copy - mutations don't affect original" , func (t * testing.T ) {
672676 rawConfig := []byte (`{
673677 "deploymentConfig": {
674678 "nodeSelector": {
@@ -684,31 +688,21 @@ func Test_GetDeploymentConfig(t *testing.T) {
684688 require .NoError (t , err )
685689
686690 // Get the deploymentConfig
687- result1 := cfg .GetDeploymentConfig ()
691+ result1 , err := cfg .GetDeploymentConfig ()
692+ require .NoError (t , err )
688693 require .NotNil (t , result1 )
689694
690- // Mutate the returned map
691- result1 ["nodeSelector" ] = map [string ]any {
692- "mutated" : "value" ,
693- }
694- result1 ["newField" ] = "added"
695+ // Mutate the returned struct
696+ result1 .NodeSelector ["mutated" ] = "value"
695697
696698 // Get deploymentConfig again - should be unaffected by mutations
697- result2 := cfg .GetDeploymentConfig ()
699+ result2 , err := cfg .GetDeploymentConfig ()
700+ require .NoError (t , err )
698701 require .NotNil (t , result2 )
699702
700703 // Original values should be intact
701- require .Equal (t , map [string ]any {
702- "nodeSelector" : map [string ]any {
703- "kubernetes.io/os" : "linux" ,
704- },
705- }, result2 )
706-
707- // New field should not exist
708- _ , exists := result2 ["newField" ]
709- require .False (t , exists )
710-
711- // result1 should have the mutations
712- require .Equal (t , "added" , result1 ["newField" ])
704+ require .Equal (t , map [string ]string {
705+ "kubernetes.io/os" : "linux" ,
706+ }, result2 .NodeSelector )
713707 })
714708}
0 commit comments