Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fakeclient instead of reactor in vmclone #10908

Merged
merged 6 commits into from
Feb 9, 2024
Merged
Prev Previous commit
Next Next commit
refactor(clone_test): drop useless snapshotcontent reactor
There is no reason to expect the snapshotContent api call,
since in the production code it does not happen.
This is a perfect example of why reactors can be bad sometimes.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
  • Loading branch information
fossedihelm committed Feb 2, 2024
commit e6ffcb98c98b417c33d03908ddb74a73b45dcfcb
24 changes: 0 additions & 24 deletions pkg/virt-controller/watch/clone/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import (
const (
snapshotResource = "virtualmachinesnapshots"
restoreResource = "virtualmachinerestores"
snapshotContentResource = "virtualmachinesnapshotcontents"
vmAPIGroup = "kubevirt.io"
snapshotAPIGroup = "snapshot.kubevirt.io"
testCloneUID = "clone-uid"
Expand Down Expand Up @@ -237,27 +236,6 @@ var _ = Describe("Clone", func() {
testutils.ExpectEvent(recorder, string(event))
}

expectSnapshotContentGet := func(vm *virtv1.VirtualMachine) {
client.Fake.PrependReactor("get", snapshotContentResource, func(action testing.Action) (handled bool, ret runtime.Object, err error) {
_, ok := action.(testing.GetAction)
Expect(ok).To(BeTrue())

content := snapshotv1alpha1.VirtualMachineSnapshotContent{
Spec: snapshotv1alpha1.VirtualMachineSnapshotContentSpec{
Source: snapshotv1alpha1.SourceSpec{
VirtualMachine: &snapshotv1alpha1.VirtualMachine{
ObjectMeta: vm.ObjectMeta,
Spec: vm.Spec,
Status: vm.Status,
},
},
},
}

return true, &content, nil
})
}

setSnapshotSource := func(vmClone *clonev1alpha1.VirtualMachineClone, snapshotName string) {
source := vmClone.Spec.Source
source.APIGroup = pointer.String(snapshotAPIGroup)
Expand Down Expand Up @@ -859,7 +837,6 @@ var _ = Describe("Clone", func() {
It("should delete smbios serial if serial is not provided", func() {
addClone(vmClone)
expectSMbiosSerial(emptySerial)
expectSnapshotContentGet(sourceVM)

controller.Execute()
})
Expand Down Expand Up @@ -1020,7 +997,6 @@ var _ = Describe("Clone", func() {
addClone(vmClone)
addSnapshot(snapshot)

expectSnapshotContentGet(sourceVM)
expectRestoreCreate(snapshot.Name, vmClone)

_, err := controller.sync(vmClone)
Expand Down