@@ -154,7 +154,7 @@ func TestApplySecurityContextConstraintsv1(t *testing.T) {
154154 }
155155 for _ , tc := range tests {
156156 t .Run (tc .name , func (t * testing.T ) {
157- newClient := securityfake .NewSimpleClientset ()
157+ newClient := securityfake .NewClientset ()
158158 // We cannot simply initialize the client because initialization is broken for SCC
159159 // https://github.com/openshift/client-go/issues/244
160160 if tc .existing != nil {
@@ -176,16 +176,46 @@ func TestApplySecurityContextConstraintsv1(t *testing.T) {
176176 t .Fatalf ("expected no error, got %v" , err )
177177 }
178178
179- if diff := cmp .Diff (tc .expectedAPICalls , newClient .Actions ()); diff != "" {
179+ if diff := cmp .Diff (tc .expectedAPICalls , clearManagedFields ( newClient .Actions () )); diff != "" {
180180 t .Errorf ("API calls differ from expected:\n %s" , diff )
181181 }
182182
183183 if tc .expectedModified != modified {
184184 t .Errorf ("expected modified %v, got %v" , tc .expectedModified , modified )
185185 }
186+
187+ if actual != nil {
188+ // The client sets managed fields, but we don't want to test that
189+ // so clear them here as they aren't present in the `expected` SCC.
190+ actual .ManagedFields = nil
191+ }
192+
186193 if diff := cmp .Diff (tc .expected (), actual ); diff != "" {
187194 t .Errorf ("SCC differs from expected:\n %s" , diff )
188195 }
189196 })
190197 }
191198}
199+
200+ // clearManagedFields clears the managed fields from the update actions
201+ // as they aren't present in the `expected` actions.
202+ // We don't want to test that this metadata is set by the client.
203+ func clearManagedFields (actions []kubetesting.Action ) []kubetesting.Action {
204+ for i := range actions {
205+ updateAction , ok := actions [i ].(kubetesting.UpdateActionImpl )
206+ if ! ok {
207+ continue
208+ }
209+
210+ metaObj , ok := updateAction .Object .(metav1.Object )
211+ if ! ok {
212+ continue
213+ }
214+
215+ metaObj .SetManagedFields (nil )
216+
217+ actions [i ] = updateAction
218+ }
219+
220+ return actions
221+ }
0 commit comments