From 4edb657c9ba7d2f68ddd1a3cb431e7aa0a232e6c Mon Sep 17 00:00:00 2001 From: David Vossel Date: Fri, 1 Mar 2019 14:12:47 -0500 Subject: [PATCH] unit tests for preventing updates until update logic is implemented Signed-off-by: David Vossel --- pkg/virt-operator/kubevirt_test.go | 56 ++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/pkg/virt-operator/kubevirt_test.go b/pkg/virt-operator/kubevirt_test.go index f04286447c27..b8ced720c7c5 100644 --- a/pkg/virt-operator/kubevirt_test.go +++ b/pkg/virt-operator/kubevirt_test.go @@ -665,11 +665,11 @@ var _ = Describe("KubeVirt Operator", func() { }).Times(times) } - shouldExpectKubeVirtUpdateFailureCondition := func() { + shouldExpectKubeVirtUpdateFailureCondition := func(reason string) { update := kvInterface.EXPECT().Update(gomock.Any()) update.Do(func(kv *v1.KubeVirt) { Expect(len(kv.Status.Conditions)).To(Equal(1)) - Expect(kv.Status.Conditions[0].Reason).To(Equal(ConditionReasonDeploymentFailedExisting)) + Expect(kv.Status.Conditions[0].Reason).To(Equal(reason)) kvInformer.GetStore().Update(kv) update.Return(kv, nil) }).Times(1) @@ -796,6 +796,56 @@ var _ = Describe("KubeVirt Operator", func() { }, 15) + // TODO this test case will be removed once updates are implemented + It("shouldn't allow updating kubevirt image tag until updates are implemented", func(done Done) { + defer close(done) + + kv := &v1.KubeVirt{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-install", + Namespace: NAMESPACE, + UID: "11111111111", + Finalizers: []string{util.KubeVirtFinalizer}, + }, + Spec: v1.KubeVirtSpec{ + ImageTag: "1.1.1", + }, + Status: v1.KubeVirtStatus{ + TargetKubeVirtVersion: "2.2.2.2", + }, + } + + addKubeVirt(kv) + + shouldExpectKubeVirtUpdateFailureCondition(ConditionReasonUpdateNotImplementedError) + controller.Execute() + }, 15) + + // TODO this test case will be removed once updates are implemented + It("shouldn't allow updating kubevirt image registry until updates are implemented", func(done Done) { + defer close(done) + + kv := &v1.KubeVirt{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-install", + Namespace: NAMESPACE, + UID: "11111111111", + Finalizers: []string{util.KubeVirtFinalizer}, + }, + Spec: v1.KubeVirtSpec{ + ImageRegistry: "someregistry1", + }, + Status: v1.KubeVirtStatus{ + TargetKubeVirtRegistry: "someregistry2", + }, + } + + addKubeVirt(kv) + + shouldExpectKubeVirtUpdateFailureCondition(ConditionReasonUpdateNotImplementedError) + controller.Execute() + }, 15) + It("should fail if KubeVirt object already exists", func(done Done) { defer close(done) @@ -838,7 +888,7 @@ var _ = Describe("KubeVirt Operator", func() { addKubeVirt(kv1) addKubeVirt(kv2) - shouldExpectKubeVirtUpdateFailureCondition() + shouldExpectKubeVirtUpdateFailureCondition(ConditionReasonDeploymentFailedExisting) controller.execute(fmt.Sprintf("%s/%s", kv2.Namespace, kv2.Name))