Skip to content

Commit

Permalink
operator image tag unit test
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <[email protected]>
  • Loading branch information
davidvossel committed Mar 8, 2019
1 parent 5e3ef21 commit 911e693
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 12 deletions.
1 change: 1 addition & 0 deletions pkg/virt-operator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ go_test(
"//pkg/kubecli:go_default_library",
"//pkg/log:go_default_library",
"//pkg/testutils:go_default_library",
"//pkg/version:go_default_library",
"//pkg/virt-operator/creation/components:go_default_library",
"//pkg/virt-operator/creation/rbac:go_default_library",
"//pkg/virt-operator/install-strategy:go_default_library",
Expand Down
79 changes: 67 additions & 12 deletions pkg/virt-operator/kubevirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ var _ = Describe("KubeVirt Operator", func() {
var informers util.Informers
var stores util.Stores

os.Setenv(util.OperatorImageEnvName, "somerepository/virt-operator:v9.9.9")
defaultImageTag := "v9.9.9"
defaultRegistry := "someregistry"
os.Setenv(util.OperatorImageEnvName, fmt.Sprintf("%s/virt-operator:%s", defaultRegistry, defaultImageTag))

var totalAdds int
var totalDeletions int
Expand Down Expand Up @@ -344,14 +346,10 @@ var _ = Describe("KubeVirt Operator", func() {
}
}

addInstallStrategy := func() {
repository := "somerepository"
version := "v9.9.9"

addInstallStrategy := func(imageTag string, imageRegistry string) {
// install strategy config
resource, _ := installstrategy.NewInstallStrategyConfigMap(NAMESPACE, version, repository)
resource, _ := installstrategy.NewInstallStrategyConfigMap(NAMESPACE, imageTag, imageRegistry)
addResource(resource)

}

addAll := func() {
Expand All @@ -363,9 +361,6 @@ var _ = Describe("KubeVirt Operator", func() {

all := make([]interface{}, 0)

// install strategy config
addInstallStrategy()

// rbac
all = append(all, rbac.GetAllCluster(NAMESPACE)...)
all = append(all, rbac.GetAllApiServer(NAMESPACE)...)
Expand Down Expand Up @@ -652,6 +647,7 @@ var _ = Describe("KubeVirt Operator", func() {
kubeClient.Fake.PrependReactor("create", "deployments", genericCreateFunc)
kubeClient.Fake.PrependReactor("create", "daemonsets", genericCreateFunc)
}

shouldExpectKubeVirtUpdate := func(times int) {
update := kvInterface.EXPECT().Update(gomock.Any())
update.Do(func(kv *v1.KubeVirt) {
Expand All @@ -660,6 +656,17 @@ var _ = Describe("KubeVirt Operator", func() {
}).Times(times)
}

shouldExpectKubeVirtUpdateVersion := func(times int, imageTag string) {
update := kvInterface.EXPECT().Update(gomock.Any())
update.Do(func(kv *v1.KubeVirt) {

Expect(kv.Status.TargetKubeVirtVersion).To(Equal(imageTag))
Expect(kv.Status.ObservedKubeVirtVersion).To(Equal(imageTag))
kvInformer.GetStore().Update(kv)
update.Return(kv, nil)
}).Times(times)
}

shouldExpectKubeVirtUpdateFailureCondition := func() {
update := kvInterface.EXPECT().Update(gomock.Any())
update.Do(func(kv *v1.KubeVirt) {
Expand Down Expand Up @@ -697,8 +704,54 @@ var _ = Describe("KubeVirt Operator", func() {
shouldExpectInstallStrategyDeletion()

addKubeVirt(kv)
addInstallStrategy()
addInstallStrategy(defaultImageTag, defaultRegistry)
controller.Execute()
}, 15)

It("should observe custom image tag in status during deploy", func(done Done) {
defer close(done)

kv := &v1.KubeVirt{
ObjectMeta: metav1.ObjectMeta{
Name: "test-install",
Namespace: NAMESPACE,
Finalizers: []string{util.KubeVirtFinalizer},
},
Spec: v1.KubeVirtSpec{
ImageTag: "custom.tag",
},
Status: v1.KubeVirtStatus{
Phase: v1.KubeVirtPhaseDeployed,
Conditions: []v1.KubeVirtCondition{
{
Type: v1.KubeVirtConditionCreated,
Status: k8sv1.ConditionTrue,
Reason: ConditionReasonDeploymentCreated,
Message: "All resources were created.",
},
{
Type: v1.KubeVirtConditionReady,
Status: k8sv1.ConditionTrue,
Reason: ConditionReasonDeploymentReady,
Message: "All components are ready.",
},
},
OperatorVersion: version.Get().String(),
},
}

// create all resources which should already exist
addKubeVirt(kv)
addAll()
// install strategy config
addInstallStrategy("custom.tag", defaultRegistry)

makeApiAndControllerReady()
makeHandlerReady()

shouldExpectKubeVirtUpdateVersion(1, "custom.tag")
controller.Execute()

}, 15)

It("should do nothing if KubeVirt object is deployed", func(done Done) {
Expand Down Expand Up @@ -734,6 +787,7 @@ var _ = Describe("KubeVirt Operator", func() {

// create all resources which should already exist
addKubeVirt(kv)
addInstallStrategy(defaultImageTag, defaultRegistry)
addAll()
makeApiAndControllerReady()
makeHandlerReady()
Expand Down Expand Up @@ -877,7 +931,7 @@ var _ = Describe("KubeVirt Operator", func() {
},
}
addKubeVirt(kv)
addInstallStrategy()
addInstallStrategy(defaultImageTag, defaultRegistry)

job := controller.generateInstallStrategyJob(kv)

Expand Down Expand Up @@ -969,6 +1023,7 @@ var _ = Describe("KubeVirt Operator", func() {
addKubeVirt(kv)

// create all resources which should be deleted
addInstallStrategy(defaultImageTag, defaultRegistry)
addAll()

shouldExpectKubeVirtUpdate(1)
Expand Down

0 comments on commit 911e693

Please sign in to comment.