Skip to content

Commit

Permalink
pkg: fix fake client usage and use delete for adding deletionTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jul 4, 2023
1 parent eec966f commit 92c834a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
12 changes: 2 additions & 10 deletions pkg/services/vmoperator/vmopmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,16 +547,8 @@ var _ = Describe("VirtualMachine tests", func() {
requeue, err = vmService.ReconcileNormal(ctx)
// There is no GC behavior in the unit test environment, so simulate it
vmService.deleteFunc = func(vm *vmoprv1.VirtualMachine) error {
if vm.GetFinalizers() == nil {
if err := ctx.Client.Delete(ctx, vm); err != nil {
return err
}
} else {
timeNow := metav1.Now()
vm.SetDeletionTimestamp(&timeNow)
if err := ctx.Client.Update(ctx, vm); err != nil {
return err
}
if err := ctx.Client.Delete(ctx, vm); err != nil {
return err
}
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/util/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ func CreateClusterContext(cluster *clusterv1.Cluster, vsphereCluster *infrav1.VS
Context: goctx.Background(),
Logger: klog.Background().WithName("controller-manager-logger"),
Scheme: scheme,
Client: testclient.NewClientBuilder().WithScheme(scheme).Build(),
Client: testclient.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(
&vmoprv1.VirtualMachineService{},
&vmoprv1.VirtualMachine{},
).Build(),
}

// Build the controller context.
Expand Down

0 comments on commit 92c834a

Please sign in to comment.