Skip to content

Commit c3866e0

Browse files
committed
Fix managedField unit tests
1 parent 093a30b commit c3866e0

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

exp/topology/desiredstate/desired_state_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,10 +1220,9 @@ func TestComputeControlPlaneVersion(t *testing.T) {
12201220
{
12211221
APIVersion: builder.InfrastructureGroupVersion.String(),
12221222
Manager: "manager",
1223-
Operation: "op",
1223+
Operation: "Apply",
12241224
Time: ptr.To(metav1.Now()),
12251225
FieldsType: "FieldsV1",
1226-
FieldsV1: &metav1.FieldsV1{},
12271226
},
12281227
},
12291228
Annotations: map[string]string{
@@ -1565,10 +1564,9 @@ func TestComputeControlPlaneVersion(t *testing.T) {
15651564
{
15661565
APIVersion: builder.InfrastructureGroupVersion.String(),
15671566
Manager: "manager",
1568-
Operation: "op",
1567+
Operation: "Apply",
15691568
Time: ptr.To(metav1.Now()),
15701569
FieldsType: "FieldsV1",
1571-
FieldsV1: &metav1.FieldsV1{},
15721570
},
15731571
})
15741572
if tt.s.Current.Cluster.Annotations == nil {

internal/controllers/machineset/machineset_controller_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,10 @@ func TestMachineSetReconcile_MachinesCreatedConditionFalseOnBadInfraRef(t *testi
10021002
request := reconcile.Request{
10031003
NamespacedName: key,
10041004
}
1005-
fakeClient := fake.NewClientBuilder().WithObjects(cluster, ms, builder.GenericInfrastructureMachineTemplateCRD.DeepCopy()).WithStatusSubresource(&clusterv1.MachineSet{}).Build()
1005+
scheme := runtime.NewScheme()
1006+
g.Expect(apiextensionsv1.AddToScheme(scheme)).To(Succeed())
1007+
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed())
1008+
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(cluster, ms, builder.GenericInfrastructureMachineTemplateCRD.DeepCopy()).WithStatusSubresource(&clusterv1.MachineSet{}).Build()
10061009

10071010
msr := &Reconciler{
10081011
Client: fakeClient,

internal/controllers/topology/cluster/cluster_controller_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,9 @@ func TestClusterReconciler_reconcileDelete(t *testing.T) {
568568
{
569569
APIVersion: builder.InfrastructureGroupVersion.String(),
570570
Manager: "manager",
571-
Operation: "op",
571+
Operation: "Apply",
572572
Time: ptr.To(metav1.Now()),
573573
FieldsType: "FieldsV1",
574-
FieldsV1: &metav1.FieldsV1{},
575574
},
576575
})
577576
if tt.cluster.Annotations == nil {
@@ -739,10 +738,9 @@ func TestReconciler_callBeforeClusterCreateHook(t *testing.T) {
739738
{
740739
APIVersion: builder.InfrastructureGroupVersion.String(),
741740
Manager: "manager",
742-
Operation: "op",
741+
Operation: "Apply",
743742
Time: ptr.To(metav1.Now()),
744743
FieldsType: "FieldsV1",
745-
FieldsV1: &metav1.FieldsV1{},
746744
},
747745
},
748746
Annotations: map[string]string{

internal/controllers/topology/cluster/patches/template_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ func TestRequestItemBuilder(t *testing.T) {
5252
{
5353
APIVersion: builder.InfrastructureGroupVersion.String(),
5454
Manager: "manager",
55-
Operation: "op",
55+
Operation: "Apply",
5656
Time: ptr.To(metav1.Now()),
5757
FieldsType: "FieldsV1",
58-
FieldsV1: &metav1.FieldsV1{Raw: []byte("fields")},
5958
},
6059
})
6160
u.SetAnnotations(map[string]string{

internal/controllers/topology/cluster/reconcile_state_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,9 @@ func TestReconcile_callAfterControlPlaneInitialized(t *testing.T) {
502502
{
503503
APIVersion: builder.InfrastructureGroupVersion.String(),
504504
Manager: "manager",
505-
Operation: "op",
505+
Operation: "Apply",
506506
Time: ptr.To(metav1.Now()),
507507
FieldsType: "FieldsV1",
508-
FieldsV1: &metav1.FieldsV1{},
509508
},
510509
})
511510
if tt.cluster.Annotations == nil {
@@ -1146,10 +1145,9 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) {
11461145
{
11471146
APIVersion: builder.InfrastructureGroupVersion.String(),
11481147
Manager: "manager",
1149-
Operation: "op",
1148+
Operation: "Apply",
11501149
Time: ptr.To(metav1.Now()),
11511150
FieldsType: "FieldsV1",
1152-
FieldsV1: &metav1.FieldsV1{},
11531151
},
11541152
})
11551153
if tt.s.Current.Cluster.Annotations == nil {

internal/util/ssa/managedfields_test.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func TestDropManagedFieldsWithFakeClient(t *testing.T) {
162162
Operation: metav1.ManagedFieldsOperationUpdate,
163163
FieldsType: "FieldsV1",
164164
FieldsV1: &metav1.FieldsV1{Raw: fieldV1},
165+
APIVersion: "v1",
165166
}},
166167
Labels: map[string]string{
167168
"label-1": "value-1",
@@ -186,10 +187,13 @@ func TestDropManagedFieldsWithFakeClient(t *testing.T) {
186187
Operation: metav1.ManagedFieldsOperationUpdate,
187188
FieldsType: "FieldsV1",
188189
FieldsV1: &metav1.FieldsV1{Raw: fieldV1},
190+
APIVersion: "v1",
189191
},
190192
{
191-
Manager: ssaManager,
192-
Operation: metav1.ManagedFieldsOperationApply,
193+
Manager: ssaManager,
194+
Operation: metav1.ManagedFieldsOperationApply,
195+
FieldsType: "FieldsV1",
196+
APIVersion: "v1",
193197
},
194198
},
195199
Labels: map[string]string{
@@ -225,7 +229,7 @@ func TestDropManagedFieldsWithFakeClient(t *testing.T) {
225229
for _, tt := range tests {
226230
t.Run(tt.name, func(t *testing.T) {
227231
g := NewWithT(t)
228-
fakeClient := fake.NewClientBuilder().WithObjects(tt.obj).Build()
232+
fakeClient := fake.NewClientBuilder().WithObjects(tt.obj).WithReturnManagedFields().Build()
229233
labelsAndAnnotationsManagedFieldPaths := []contract.Path{
230234
{"f:metadata", "f:annotations"},
231235
{"f:metadata", "f:labels"},
@@ -414,8 +418,10 @@ func TestCleanUpManagedFieldsForSSAAdoptionWithFakeClient(t *testing.T) {
414418
Name: "cm-1",
415419
Namespace: "default",
416420
ManagedFields: []metav1.ManagedFieldsEntry{{
417-
Manager: classicManager,
418-
Operation: metav1.ManagedFieldsOperationUpdate,
421+
Manager: classicManager,
422+
Operation: metav1.ManagedFieldsOperationUpdate,
423+
FieldsType: "FieldsV1",
424+
APIVersion: "v1",
419425
}},
420426
},
421427
Data: map[string]string{
@@ -427,8 +433,10 @@ func TestCleanUpManagedFieldsForSSAAdoptionWithFakeClient(t *testing.T) {
427433
Name: "cm-1",
428434
Namespace: "default",
429435
ManagedFields: []metav1.ManagedFieldsEntry{{
430-
Manager: ssaManager,
431-
Operation: metav1.ManagedFieldsOperationApply,
436+
Manager: ssaManager,
437+
Operation: metav1.ManagedFieldsOperationApply,
438+
FieldsType: "FieldsV1",
439+
APIVersion: "v1",
432440
}},
433441
},
434442
Data: map[string]string{
@@ -441,12 +449,16 @@ func TestCleanUpManagedFieldsForSSAAdoptionWithFakeClient(t *testing.T) {
441449
Namespace: "default",
442450
ManagedFields: []metav1.ManagedFieldsEntry{
443451
{
444-
Manager: classicManager,
445-
Operation: metav1.ManagedFieldsOperationUpdate,
452+
Manager: classicManager,
453+
Operation: metav1.ManagedFieldsOperationUpdate,
454+
FieldsType: "FieldsV1",
455+
APIVersion: "v1",
446456
},
447457
{
448-
Manager: ssaManager,
449-
Operation: metav1.ManagedFieldsOperationApply,
458+
Manager: ssaManager,
459+
Operation: metav1.ManagedFieldsOperationApply,
460+
FieldsType: "FieldsV1",
461+
APIVersion: "v1",
450462
},
451463
},
452464
},
@@ -485,7 +497,7 @@ func TestCleanUpManagedFieldsForSSAAdoptionWithFakeClient(t *testing.T) {
485497
for _, tt := range tests {
486498
t.Run(tt.name, func(t *testing.T) {
487499
g := NewWithT(t)
488-
fakeClient := fake.NewClientBuilder().WithObjects(tt.obj).Build()
500+
fakeClient := fake.NewClientBuilder().WithObjects(tt.obj).WithReturnManagedFields().Build()
489501
g.Expect(CleanUpManagedFieldsForSSAAdoption(ctx, fakeClient, tt.obj, ssaManager)).Should(Succeed())
490502
g.Expect(tt.obj.GetManagedFields()).Should(
491503
ContainElement(MatchManagedFieldsEntry(ssaManager, metav1.ManagedFieldsOperationApply)))

0 commit comments

Comments
 (0)