Skip to content

Commit baac3e8

Browse files
author
irit.go
committed
add functional tests for import and cloning events
1 parent 52453a9 commit baac3e8

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

tests/datavolume_test.go

+31-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package tests_test
22

33
import (
44
"fmt"
5+
"strings"
6+
"time"
57

68
. "github.com/onsi/ginkgo"
79
. "github.com/onsi/gomega"
@@ -11,12 +13,19 @@ import (
1113
"k8s.io/api/core/v1"
1214
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1315

16+
"kubevirt.io/containerized-data-importer/pkg/controller"
17+
"kubevirt.io/containerized-data-importer/tests"
1418
"kubevirt.io/containerized-data-importer/tests/framework"
1519
"kubevirt.io/containerized-data-importer/tests/utils"
1620

1721
cdiv1 "kubevirt.io/containerized-data-importer/pkg/apis/datavolumecontroller/v1alpha1"
1822
)
1923

24+
const (
25+
pollingInterval = 2 * time.Second
26+
timeout = 60 * time.Second
27+
)
28+
2029
var _ = Describe("DataVolume tests", func() {
2130

2231
var sourcePvc *v1.PersistentVolumeClaim
@@ -37,7 +46,7 @@ var _ = Describe("DataVolume tests", func() {
3746
})
3847

3948
Describe("Verify DataVolume", func() {
40-
table.DescribeTable("with http import source should", func(url string, phase cdiv1.DataVolumePhase, dataVolumeName string) {
49+
table.DescribeTable("with http import source should", func(url string, phase cdiv1.DataVolumePhase, dataVolumeName string, eventReasons []string) {
4150
dataVolume := utils.NewDataVolumeWithHTTPImport(dataVolumeName, "1Gi", url)
4251

4352
By(fmt.Sprintf("creating new datavolume %s", dataVolume.Name))
@@ -52,13 +61,24 @@ var _ = Describe("DataVolume tests", func() {
5261
_, err = f.K8sClient.CoreV1().PersistentVolumeClaims(dataVolume.Namespace).Get(dataVolume.Name, metav1.GetOptions{})
5362
Expect(err).ToNot(HaveOccurred())
5463

64+
By(fmt.Sprint("Verifying events occured"))
65+
66+
for _, eventReason := range eventReasons {
67+
Eventually(func() bool {
68+
events, err := tests.RunKubectlCommand(f, "get", "events", "-n", dataVolume.Namespace)
69+
Expect(err).NotTo(HaveOccurred())
70+
return strings.Contains(events, eventReason)
71+
}, timeout, pollingInterval).Should(BeTrue())
72+
73+
}
74+
5575
err = utils.DeleteDataVolume(f.CdiClient, f.Namespace.Name, dataVolume)
5676
Expect(err).ToNot(HaveOccurred())
5777

5878
},
59-
table.Entry("succeed when given valid url", utils.TinyCoreIsoURL, cdiv1.Succeeded, "dv-phase-test-1"),
60-
table.Entry("fail due to invalid DNS entry", "http://i-made-this-up.kube-system/tinyCore.iso", cdiv1.Failed, "dv-phase-test-2"),
61-
table.Entry("fail due to file not found", utils.TinyCoreIsoURL+"not.real.file", cdiv1.Failed, "dv-phase-test-3"),
79+
table.Entry("succeed when given valid url", utils.TinyCoreIsoURL, cdiv1.Succeeded, "dv-phase-test-1", []string{controller.ImportScheduled, controller.ImportSucceeded}),
80+
table.Entry("fail due to invalid DNS entry", "http://i-made-this-up.kube-system/tinyCore.iso", cdiv1.Failed, "dv-phase-test-2", []string{controller.ImportScheduled, controller.ImportInProgress}),
81+
table.Entry("fail due to file not found", utils.TinyCoreIsoURL+"not.real.file", cdiv1.Failed, "dv-phase-test-3", []string{controller.ImportScheduled, controller.ImportInProgress}),
6282
)
6383

6484
table.DescribeTable("with clone source should", func(command string, phase cdiv1.DataVolumePhase, dataVolumeName string) {
@@ -89,6 +109,13 @@ var _ = Describe("DataVolume tests", func() {
89109
Expect(f.VerifyTargetPVCContent(f.Namespace, targetPvc, testFile, fillData)).To(BeTrue())
90110
}
91111

112+
By(fmt.Sprintf("Verifying event %s occured", controller.CloneSucceeded))
113+
Eventually(func() bool {
114+
events, err := tests.RunKubectlCommand(f, "get", "events", "-n", dataVolume.Namespace)
115+
Expect(err).NotTo(HaveOccurred())
116+
return strings.Contains(events, controller.CloneSucceeded)
117+
}, timeout, pollingInterval).Should(BeTrue())
118+
92119
err = utils.DeleteDataVolume(f.CdiClient, f.Namespace.Name, dataVolume)
93120
Expect(err).ToNot(HaveOccurred())
94121

0 commit comments

Comments
 (0)