@@ -86,105 +86,3 @@ func loadAllTestsOrPanic(t *testing.T, fromDir string) []TestCase {
8686 }
8787 return tests
8888}
89-
90- func TestMergeEnvVars (t * testing.T ) {
91- tests := []struct {
92- name string
93- existing []corev1.EnvVar
94- toAdd []corev1.EnvVar
95- expected map [string ]string // Using map for easier assertion since order is non-deterministic
96- }{
97- {
98- name : "no duplicates - variables are combined" ,
99- existing : []corev1.EnvVar {
100- {Name : "VAR1" , Value : "value1" },
101- {Name : "VAR2" , Value : "value2" },
102- },
103- toAdd : []corev1.EnvVar {
104- {Name : "VAR3" , Value : "value3" },
105- },
106- expected : map [string ]string {
107- "VAR1" : "value1" ,
108- "VAR2" : "value2" ,
109- "VAR3" : "value3" ,
110- },
111- },
112- {
113- name : "toAdd overrides existing - new value wins" ,
114- existing : []corev1.EnvVar {
115- {Name : "VAR1" , Value : "old" },
116- {Name : "VAR2" , Value : "keep" },
117- },
118- toAdd : []corev1.EnvVar {
119- {Name : "VAR1" , Value : "new" },
120- },
121- expected : map [string ]string {
122- "VAR1" : "new" ,
123- "VAR2" : "keep" ,
124- },
125- },
126- {
127- name : "empty existing - only toAdd returned" ,
128- existing : []corev1.EnvVar {},
129- toAdd : []corev1.EnvVar {
130- {Name : "VAR1" , Value : "value1" },
131- },
132- expected : map [string ]string {
133- "VAR1" : "value1" ,
134- },
135- },
136- {
137- name : "empty toAdd - only existing returned" ,
138- existing : []corev1.EnvVar {
139- {Name : "VAR1" , Value : "value1" },
140- },
141- toAdd : []corev1.EnvVar {},
142- expected : map [string ]string {
143- "VAR1" : "value1" ,
144- },
145- },
146- {
147- name : "both empty - empty result" ,
148- existing : []corev1.EnvVar {},
149- toAdd : []corev1.EnvVar {},
150- expected : map [string ]string {},
151- },
152- {
153- name : "multiple duplicates - all overridden" ,
154- existing : []corev1.EnvVar {
155- {Name : "VAR1" , Value : "old1" },
156- {Name : "VAR2" , Value : "old2" },
157- {Name : "VAR3" , Value : "keep" },
158- },
159- toAdd : []corev1.EnvVar {
160- {Name : "VAR1" , Value : "new1" },
161- {Name : "VAR2" , Value : "new2" },
162- },
163- expected : map [string ]string {
164- "VAR1" : "new1" ,
165- "VAR2" : "new2" ,
166- "VAR3" : "keep" ,
167- },
168- },
169- }
170-
171- for _ , tt := range tests {
172- t .Run (tt .name , func (t * testing.T ) {
173- result := MergeEnvVars (tt .existing , tt .toAdd )
174-
175- // Convert result to map for comparison (order doesn't matter)
176- resultMap := make (map [string ]string )
177- for _ , env := range result {
178- resultMap [env .Name ] = env .Value
179- }
180-
181- // Verify length matches
182- assert .Equal (t , len (tt .expected ), len (resultMap ), "Result should have correct number of env vars" )
183-
184- // Verify each expected env var
185- for name , value := range tt .expected {
186- assert .Equal (t , value , resultMap [name ], "Env var %s should have correct value" , name )
187- }
188- })
189- }
190- }
0 commit comments