From 6de9f349f200aef535dce23e9d308e8042ee675d Mon Sep 17 00:00:00 2001 From: marbarta Date: Tue, 25 Jul 2023 11:20:48 +0200 Subject: [PATCH] refactor alltestCases and live test it --- .github/workflows/e2e-test.yaml | 10 --------- tests/e2e/koperator_suite_test.go | 2 +- ...st_alltestcase.go => test_alltestcases.go} | 20 +++++++++++------- tests/e2e/test_install.go | 2 +- tests/e2e/test_install_cluster.go | 21 ++----------------- tests/e2e/test_produce_consume.go | 21 ++----------------- tests/e2e/test_uninstall.go | 13 +----------- tests/e2e/test_uninstall_cluster.go | 21 ++----------------- 8 files changed, 21 insertions(+), 89 deletions(-) rename tests/e2e/{test_alltestcase.go => test_alltestcases.go} (65%) diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index 172c03dcf6..e3acc87cd8 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -70,13 +70,3 @@ jobs: comment_mode: off files: | tests/e2e/reports/e2e_*.xml - - # - name: E2E Test Report - # uses: dorny/test-reporter@v1 - # if: always() - # with: - # name: E2E tests - # path: "tests/e2e/reports/e2e_*.xml" - # reporter: jest-junit - # fail-on-error: true - diff --git a/tests/e2e/koperator_suite_test.go b/tests/e2e/koperator_suite_test.go index 89f0218ecc..a1ec25d02d 100644 --- a/tests/e2e/koperator_suite_test.go +++ b/tests/e2e/koperator_suite_test.go @@ -42,7 +42,7 @@ func beforeSuite() (tests.TestPool, error) { } //classifier := MockTests() - classifier := tests.NewClassifier(k8sClusterPool, testCaseInstall) + classifier := tests.NewClassifier(k8sClusterPool, alltestCase) var testPool tests.TestPool testStrategy := viper.GetString(config.Tests.TestStrategy) diff --git a/tests/e2e/test_alltestcase.go b/tests/e2e/test_alltestcases.go similarity index 65% rename from tests/e2e/test_alltestcase.go rename to tests/e2e/test_alltestcases.go index 4673553dbf..0a4c185a3b 100644 --- a/tests/e2e/test_alltestcase.go +++ b/tests/e2e/test_alltestcases.go @@ -23,7 +23,7 @@ import ( var alltestCase = tests.TestCase{ TestDuration: 10 * time.Minute, - TestName: "Testing e2e test altogether", + TestName: "ALL_TESTCASE", TestFn: allTestCase, } @@ -32,12 +32,16 @@ func allTestCase(kubectlOptions k8s.KubectlOptions) { var snapshottedInfo = &clusterSnapshot{} snapshotCluster(snapshottedInfo) testInstall(kubectlOptions) - testInstallZookeeperCluster() - testInstallKafkaCluster("../../config/samples/simplekafkacluster.yaml") - testUninstallKafkaCluster() - testInstallKafkaCluster("../../config/samples/simplekafkacluster_ssl.yaml") - testUninstallKafkaCluster() - testUninstallZookeeperCluster() - testUninstall() + testInstallZookeeperCluster(kubectlOptions) + testInstallKafkaCluster(kubectlOptions, "../../config/samples/simplekafkacluster.yaml") + testProduceConsumeExternal(kubectlOptions, "") + testProduceConsumeInternal(kubectlOptions) + testUninstallKafkaCluster(kubectlOptions) + testInstallKafkaCluster(kubectlOptions, "../../config/samples/simplekafkacluster_ssl.yaml") + testProduceConsumeExternal(kubectlOptions, "") + testProduceConsumeInternal(kubectlOptions) + testUninstallKafkaCluster(kubectlOptions) + testUninstallZookeeperCluster(kubectlOptions) + testUninstall(kubectlOptions) snapshotClusterAndCompare(snapshottedInfo) } diff --git a/tests/e2e/test_install.go b/tests/e2e/test_install.go index 639092bdfd..8dc51faeb5 100644 --- a/tests/e2e/test_install.go +++ b/tests/e2e/test_install.go @@ -25,7 +25,7 @@ import ( var testCaseInstall = tests.TestCase{ TestDuration: 4 * time.Minute, - TestName: "Install TestCase", + TestName: "INSTALL_TESTCASE", TestFn: testInstall, } diff --git a/tests/e2e/test_install_cluster.go b/tests/e2e/test_install_cluster.go index 4f1f827882..6c845b830d 100644 --- a/tests/e2e/test_install_cluster.go +++ b/tests/e2e/test_install_cluster.go @@ -17,34 +17,17 @@ package e2e import ( "github.com/gruntwork-io/terratest/modules/k8s" . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" ) -func testInstallZookeeperCluster() bool { +func testInstallZookeeperCluster(kubectlOptions k8s.KubectlOptions) bool { return When("Installing Zookeeper cluster", func() { - var kubectlOptions k8s.KubectlOptions - var err error - - It("Acquiring K8s config and context", func() { - kubectlOptions, err = kubectlOptionsForCurrentContext() - Expect(err).NotTo(HaveOccurred()) - }) - kubectlOptions.Namespace = zookeeperOperatorHelmDescriptor.Namespace requireCreatingZookeeperCluster(kubectlOptions) }) } -func testInstallKafkaCluster(kafkaClusterManifestPath string) bool { +func testInstallKafkaCluster(kubectlOptions k8s.KubectlOptions, kafkaClusterManifestPath string) bool { return When("Installing Kafka cluster", func() { - var kubectlOptions k8s.KubectlOptions - var err error - - It("Acquiring K8s config and context", func() { - kubectlOptions, err = kubectlOptionsForCurrentContext() - Expect(err).NotTo(HaveOccurred()) - }) - kubectlOptions.Namespace = koperatorLocalHelmDescriptor.Namespace requireCreatingKafkaCluster(kubectlOptions, kafkaClusterManifestPath) }) diff --git a/tests/e2e/test_produce_consume.go b/tests/e2e/test_produce_consume.go index a20b0f1bee..5cf6d951ec 100644 --- a/tests/e2e/test_produce_consume.go +++ b/tests/e2e/test_produce_consume.go @@ -3,19 +3,10 @@ package e2e import ( "github.com/gruntwork-io/terratest/modules/k8s" . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" ) -func testProduceConsumeInternal() bool { +func testProduceConsumeInternal(kubectlOptions k8s.KubectlOptions) bool { return When("Internally produce and consume message to/from Kafka cluster", func() { - var kubectlOptions k8s.KubectlOptions - var err error - - It("Acquiring K8s config and context", func() { - kubectlOptions, err = kubectlOptionsForCurrentContext() - Expect(err).NotTo(HaveOccurred()) - }) - kubectlOptions.Namespace = koperatorLocalHelmDescriptor.Namespace requireDeployingKcatPod(kubectlOptions, kcatPodName) @@ -26,16 +17,8 @@ func testProduceConsumeInternal() bool { }) } -func testProduceConsumeExternal(tlsSecretName string) bool { +func testProduceConsumeExternal(kubectlOptions k8s.KubectlOptions, tlsSecretName string) bool { return When("Externally produce and consume message to/from Kafka cluster", func() { - var kubectlOptions k8s.KubectlOptions - var err error - - It("Acquiring K8s config and context", func() { - kubectlOptions, err = kubectlOptionsForCurrentContext() - Expect(err).NotTo(HaveOccurred()) - }) - kubectlOptions.Namespace = koperatorLocalHelmDescriptor.Namespace requireDeployingKafkaTopic(kubectlOptions, testExternalTopicName) diff --git a/tests/e2e/test_uninstall.go b/tests/e2e/test_uninstall.go index 6c1bdaf3d6..3cb9f6b917 100644 --- a/tests/e2e/test_uninstall.go +++ b/tests/e2e/test_uninstall.go @@ -20,24 +20,14 @@ import ( . "github.com/onsi/gomega" ) -func testUninstall() bool { +func testUninstall(kubectlOptions k8s.KubectlOptions) bool { return When("Uninstalling Koperator and dependencies", Ordered, func() { - var kubectlOptions k8s.KubectlOptions - var err error - When("Initializing", func() { - It("Acquiring K8s config and context", func() { - kubectlOptions, err = kubectlOptionsForCurrentContext() - Expect(err).NotTo(HaveOccurred()) - }) - It("Setting globals", func() { err := dependencyCRDs.Initialize(kubectlOptions) Expect(err).NotTo(HaveOccurred()) }) - }) - requireUninstallingKoperator(k8s.KubectlOptions{ ContextName: kubectlOptions.ContextName, ConfigPath: kubectlOptions.ConfigPath, @@ -58,6 +48,5 @@ func testUninstall() bool { ConfigPath: kubectlOptions.ConfigPath, Namespace: certManagerHelmDescriptor.Namespace, }) - }) } diff --git a/tests/e2e/test_uninstall_cluster.go b/tests/e2e/test_uninstall_cluster.go index 78d71aad16..e39c381ad5 100644 --- a/tests/e2e/test_uninstall_cluster.go +++ b/tests/e2e/test_uninstall_cluster.go @@ -17,35 +17,18 @@ package e2e import ( "github.com/gruntwork-io/terratest/modules/k8s" . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" ) -func testUninstallZookeeperCluster() bool { +func testUninstallZookeeperCluster(kubectlOptions k8s.KubectlOptions) bool { return When("Uninstalling Zookeeper cluster", func() { - var kubectlOptions k8s.KubectlOptions - var err error - - It("Acquiring K8s config and context", func() { - kubectlOptions, err = kubectlOptionsForCurrentContext() - Expect(err).NotTo(HaveOccurred()) - }) - kubectlOptions.Namespace = zookeeperOperatorHelmDescriptor.Namespace requireDeleteZookeeperCluster(kubectlOptions, zookeeperClusterName) }) } -func testUninstallKafkaCluster() bool { +func testUninstallKafkaCluster(kubectlOptions k8s.KubectlOptions) bool { return When("Uninstalling Kafka cluster", func() { - var kubectlOptions k8s.KubectlOptions - var err error - - It("Acquiring K8s config and context", func() { - kubectlOptions, err = kubectlOptionsForCurrentContext() - Expect(err).NotTo(HaveOccurred()) - }) - kubectlOptions.Namespace = koperatorLocalHelmDescriptor.Namespace requireDeleteKafkaCluster(kubectlOptions, kafkaClusterName) })