Skip to content

Commit ffe4646

Browse files
Merge pull request #1340 from JoelSpeed/update-golangci-lint
NO-ISSUE: Update fake clientsets to NewClientset
2 parents 58f3d5e + d5f7201 commit ffe4646

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

lib/resourceapply/security_test.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

pkg/cvo/cvo_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func TestOperator_sync(t *testing.T) {
503503
},
504504
namespace: "test",
505505
name: "default",
506-
client: fake.NewSimpleClientset(
506+
client: fake.NewClientset(
507507
&configv1.ClusterVersion{
508508
ObjectMeta: metav1.ObjectMeta{
509509
Name: "default",
@@ -560,7 +560,7 @@ func TestOperator_sync(t *testing.T) {
560560
},
561561
namespace: "test",
562562
name: "default",
563-
client: fake.NewSimpleClientset(
563+
client: fake.NewClientset(
564564
&configv1.ClusterVersion{
565565
ObjectMeta: metav1.ObjectMeta{
566566
Name: "default",
@@ -4224,7 +4224,7 @@ func Test_loadReleaseVerifierFromConfigMap(t *testing.T) {
42244224
tt.update.Manifests = ms
42254225
}
42264226
t.Run(tt.name, func(t *testing.T) {
4227-
f := kfake.NewSimpleClientset()
4227+
f := kfake.NewClientset()
42284228
got, store, err := loadConfigMapVerifierDataFromUpdate(tt.update, sigstore.DefaultClient, f.CoreV1(), &serial.Store{})
42294229
if err == nil {
42304230
if tt.expectedError != "" {

pkg/featuregates/featurechangestopper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestTechPreviewChangeStopper(t *testing.T) {
9999
tt.startingCvoFeatureGates = CvoGates{unknownVersion: true}
100100
}
101101

102-
client := fakeconfigv1client.NewSimpleClientset(fg)
102+
client := fakeconfigv1client.NewClientset(fg)
103103

104104
informerFactory := configv1informer.NewSharedInformerFactory(client, 0)
105105
c, err := NewChangeStopper(informerFactory.Config().V1().FeatureGates(), tt.startingRequiredFeatureSet, tt.startingCvoFeatureGates)

0 commit comments

Comments
 (0)