From 651a2c8b51a32b161901bafaafdd30a14c32a3a0 Mon Sep 17 00:00:00 2001 From: Mihai Alexandrescu Date: Mon, 28 Aug 2023 16:46:23 +0300 Subject: [PATCH] update testcase logic; use local kafkatopic struct; use local tempfile function --- tests/e2e/k8s.go | 28 +-- tests/e2e/kafka.go | 10 +- tests/e2e/kafkatopic_webhook.go | 323 ++---------------------------- tests/e2e/koperator_suite_test.go | 26 +-- 4 files changed, 30 insertions(+), 357 deletions(-) diff --git a/tests/e2e/k8s.go b/tests/e2e/k8s.go index c1bd7b740..ccd7e8209 100644 --- a/tests/e2e/k8s.go +++ b/tests/e2e/k8s.go @@ -65,14 +65,9 @@ func applyK8sResourceManifest(kubectlOptions k8s.KubectlOptions, manifestPath st // applyK8sResourceManifestFromString applies the specified manifest in string format to the provided // kubectl context and namespace. func applyK8sResourceManifestFromString(kubectlOptions k8s.KubectlOptions, manifest string, extraArgs ...string) error { - // Replicating terratest's k8s.KubectlApplyFromStringE but with the possibility of a variadic argument that allows options like --dry-run - // - // TODO: look for a different implementation for temp files because terratest's version uses the composite test name to generate - // the temp file name which, in our case, includes all the descriptive Ginkgo statements (which are by design quite verbose). - // That can lead to erroring out on temp file creation based on the file name being too long. - tmpfile, err := k8s.StoreConfigToTempFileE(GinkgoT(), manifest) + tmpfile, err := createTempFileFromBytes([]byte(manifest), "", "", 0) if err != nil { - return err + return fmt.Errorf("storing provided manifest data into temp file failed: %w", err) } defer os.Remove(tmpfile) @@ -81,7 +76,7 @@ func applyK8sResourceManifestFromString(kubectlOptions k8s.KubectlOptions, manif // applyK8sResourceFromTemplate generates manifest from the specified go-template based on values // and applies the specified manifest to the provided kubectl context and namespace. -func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFile string, values map[string]any, extraArgs ...string) error { +func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFile string, values any, extraArgs ...string) error { By(fmt.Sprintf("Generating k8s manifest from template %s", templateFile)) var manifest bytes.Buffer rawTemplate, err := os.ReadFile(templateFile) @@ -93,24 +88,7 @@ func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFil if err != nil { return err } - return applyK8sResourceManifestFromString(kubectlOptions, manifest.String(), extraArgs...) -} -// applyK8sResourceFromTemplate generates manifest from the specified go-template based on values -// and applies the specified manifest to the provided kubectl context and namespace. -func applyK8sResourceFromTemplate_2(kubectlOptions k8s.KubectlOptions, templateFile string, values any, extraArgs ...string) error { - By(fmt.Sprintf("Generating k8s manifest from template %s", templateFile)) - var manifest bytes.Buffer - rawTemplate, err := os.ReadFile(templateFile) - if err != nil { - return err - } - t := template.Must(template.New("template").Funcs(sprig.TxtFuncMap()).Parse(string(rawTemplate))) - err = t.Execute(&manifest, values) - if err != nil { - return err - } - fmt.Printf("###\nManifest is :\n%s\n###\n", manifest.String()) return applyK8sResourceManifestFromString(kubectlOptions, manifest.String(), extraArgs...) } diff --git a/tests/e2e/kafka.go b/tests/e2e/kafka.go index 316c95fcc..1561a45fa 100644 --- a/tests/e2e/kafka.go +++ b/tests/e2e/kafka.go @@ -35,14 +35,6 @@ func requireDeleteKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName string // requireDeployingKafkaTopic deploys a kafkaTopic resource from a template func requireDeployingKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName string) { It("Deploying KafkaTopic CR", func() { - // err := applyK8sResourceFromTemplate(kubectlOptions, - // kafkaTopicTemplate, - // map[string]interface{}{ - // "Name": topicName, - // "TopicName": topicName, - // "Namespace": kubectlOptions.Namespace, - // }, - // ) values := kafkaTopicTemplateData{ Annotations: []string{"managedBy: koperator"}, ClusterRef: kafkaTopicClusterRef{ @@ -56,7 +48,7 @@ func requireDeployingKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName str TopicName: topicName, } - err := applyK8sResourceFromTemplate_2(kubectlOptions, kafkaTopicTemplate, values) + err := applyK8sResourceFromTemplate(kubectlOptions, kafkaTopicTemplate, values) Expect(err).ShouldNot(HaveOccurred()) diff --git a/tests/e2e/kafkatopic_webhook.go b/tests/e2e/kafkatopic_webhook.go index be44c3e12..d4e880ee3 100644 --- a/tests/e2e/kafkatopic_webhook.go +++ b/tests/e2e/kafkatopic_webhook.go @@ -15,7 +15,6 @@ package e2e import ( - "fmt" "strings" "github.com/gruntwork-io/terratest/modules/k8s" @@ -36,14 +35,11 @@ func testWebhookKafkaTopic(kafkaCluster types.NamespacedName) { kubectlOptions.Namespace = kafkaCluster.Namespace - //testWebhookCreateKafkaTopic(kubectlOptions, kafkaCluster) - //testWebhookUpdateKafkaTopic(kubectlOptions, kafkaCluster) - - testWebhookCreateKafkaTopic_2(kubectlOptions, kafkaCluster) - testWebhookUpdateKafkaTopic_2(kubectlOptions, kafkaCluster) + testWebhookCreateKafkaTopic(kubectlOptions, kafkaCluster) + testWebhookUpdateKafkaTopic(kubectlOptions, kafkaCluster) } -func testWebhookCreateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaCluster types.NamespacedName) bool { +func testWebhookCreateKafkaTopic(kubectlOptions k8s.KubectlOptions, kafkaCluster types.NamespacedName) bool { return When("Testing KafkaTopic Create", func() { BeforeAll(func() { Expect(isExistingK8SResource(kubectlOptions, kafkaKind, kafkaCluster.Name)).To(BeTrue()) @@ -64,7 +60,7 @@ func testWebhookCreateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(2)), TopicName: testInternalTopicName, } - err := applyK8sResourceFromTemplate_2( + err := applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -93,7 +89,7 @@ func testWebhookCreateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(0)), // Note: This is a deliberately inserted error for this test case. TopicName: testInternalTopicName, } - err := applyK8sResourceFromTemplate_2( + err := applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -126,7 +122,7 @@ func testWebhookCreateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(10)), // Note: This is a deliberately inserted error for this test case. TopicName: testInternalTopicName, } - err := applyK8sResourceFromTemplate_2( + err := applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -162,7 +158,7 @@ func testWebhookCreateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(2)), TopicName: overlappingTopicName, // Note: This is a deliberately inserted error for this test case. } - err := applyK8sResourceFromTemplate_2( + err := applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -190,7 +186,7 @@ func testWebhookCreateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(2)), TopicName: overlappingTopicName, // Note: This is a deliberately inserted error for this test case. } - err = applyK8sResourceFromTemplate_2( + err = applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -217,7 +213,7 @@ func testWebhookCreateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust }) } -func testWebhookUpdateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaCluster types.NamespacedName) bool { +func testWebhookUpdateKafkaTopic(kubectlOptions k8s.KubectlOptions, kafkaCluster types.NamespacedName) bool { return When("Testing KafkaTopic Update", func() { BeforeAll(func() { Expect(isExistingK8SResource(kubectlOptions, kafkaKind, kafkaCluster.Name)).To(BeTrue()) @@ -241,7 +237,7 @@ func testWebhookUpdateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(2)), TopicName: testInternalTopicName, } - err := applyK8sResourceFromTemplate_2( + err := applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -275,7 +271,7 @@ func testWebhookUpdateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(0)), // Note: This is a deliberately inserted error for this test case. TopicName: testInternalTopicName, } - err := applyK8sResourceFromTemplate_2( + err := applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -315,7 +311,7 @@ func testWebhookUpdateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(2)), TopicName: overlappingTopicName, // Note: This is a deliberately inserted error for this test case. } - err := applyK8sResourceFromTemplate_2( + err := applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -343,7 +339,7 @@ func testWebhookUpdateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust ReplicationFactor: ptr.To(int32(2)), TopicName: overlappingTopicName, // Note: This is a deliberately inserted error for this test case. } - err = applyK8sResourceFromTemplate_2( + err = applyK8sResourceFromTemplate( kubectlOptions, kafkaTopicTemplate, caseData, @@ -370,296 +366,3 @@ func testWebhookUpdateKafkaTopic_2(kubectlOptions k8s.KubectlOptions, kafkaClust requireDeleteKafkaTopic(kubectlOptions, testInternalTopicName) }) } - -func testWebhookCreateKafkaTopic(kubectlOptions k8s.KubectlOptions, kafkaCluster types.NamespacedName) bool { - return When("Testing KafkaTopic Create", func() { - BeforeAll(func() { - Expect(isExistingK8SResource(kubectlOptions, kafkaKind, kafkaClusterName)).To(BeTrue()) - }) - - const nonExistent string = "non-existent" - - baseKafkaTopicTemplateValues := baseKafkaTopicData( - types.NamespacedName{Name: testInternalTopicName, Namespace: kubectlOptions.Namespace}, - kafkaCluster, - ) - - It("Test non-existent KafkaCluster", func() { - caseData := copyMapWithStringKeys(baseKafkaTopicTemplateValues) - caseData["ClusterRef"] = map[string]string{ - "Name": nonExistent, - "Namespace": kafkaCluster.Namespace, - } - err := applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal" is invalid: spec.clusterRef.name: Invalid value: "non-existent": kafkaCluster 'non-existent' in the namespace 'kafka' does not exist - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(1)) - Expect(err.Error()).To( - ContainSubstring("The KafkaTopic %[1]q is invalid: spec.clusterRef.name: Invalid value: %[2]q: kafkaCluster '%[2]s' in the namespace '%[3]s' does not exist", - caseData["Name"], nonExistent, kubectlOptions.Namespace), - ) - }) - - It("Test 0 partitions and replicationFactor", func() { - caseData := copyMapWithStringKeys(baseKafkaTopicTemplateValues) - caseData["Partitions"] = "0" - caseData["ReplicationFactor"] = "0" - err := applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal" is invalid: - // * spec.partitions: Invalid value: 0: number of partitions must be larger than 0 (or set it to be -1 to use the broker's default) - // * spec.replicationFactor: Invalid value: 0: replication factor must be larger than 0 (or set it to be -1 to use the broker's default) - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(3)) - Expect(err.Error()).To(And( - ContainSubstring("The KafkaTopic %q is invalid:", caseData["Name"]), - ContainSubstring("spec.partitions: Invalid value: %s: number of partitions must be larger than 0 (or set it to be -1 to use the broker's default)", caseData["Partitions"]), - ContainSubstring("spec.replicationFactor: Invalid value: %s: replication factor must be larger than 0 (or set it to be -1 to use the broker's default)", caseData["ReplicationFactor"]), - )) - }) - - // In the current validation webhook implementation, this case can only be encountered on a Create operation - It("Test ReplicationFactor larger than number of brokers", func() { - caseData := copyMapWithStringKeys(baseKafkaTopicTemplateValues) - caseData["ReplicationFactor"] = "10" - err := applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal" is invalid: spec.replicationFactor: Invalid value: 10: replication factor is larger than the number of nodes in the kafka cluster (available brokers: 3) - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(1)) - Expect(err.Error()).To( - ContainSubstring("The KafkaTopic %[1]q is invalid: spec.replicationFactor: Invalid value: %[2]s: replication factor is larger than the number of nodes in the kafka cluster", - caseData["Name"], caseData["ReplicationFactor"]), - ) - }) - - // Test case involving existing CRs but not necessarily an Update operation - When("Testing conflicts similar CRs", Ordered, func() { - requireDeployingKafkaTopic(kubectlOptions, testInternalTopicName) - - It("Testing conflict on spec.name", func() { - caseData := copyMapWithStringKeys(baseKafkaTopicTemplateValues) - - switch v := caseData["Name"].(type) { - case string: - caseData["Name"] = v + "-different-cr-name" - case fmt.Stringer: - caseData["Name"] = v.String() + "-different-cr-name" - default: - caseData["Name"] = nonExistent - } - - By("With managedBy koperator annotation") - caseData["Annotations"] = []string{"managedBy: koperator"} - err := applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal-different-cr-name" is invalid: spec.name: Invalid value: "topic-test-internal": kafkaTopic CR 'topic-test-internal' in namesapce 'kafka' is already referencing to Kafka topic 'topic-test-internal' - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(1)) - Expect(err.Error()).To( - ContainSubstring("The KafkaTopic %[1]q is invalid: spec.name: Invalid value: %[2]q: kafkaTopic CR '%[2]s' in namesapce '%[3]s' is already referencing to Kafka topic '%[2]s'", - caseData["Name"], testInternalTopicName, kubectlOptions.Namespace), - ) - - By("Without managedBy koperator annotation") - caseData["Annotations"] = []string{} - err = applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal-different-cr-name" is invalid: - // * spec.name: Invalid value: "topic-test-internal": kafkaTopic CR 'topic-test-internal' in namesapce 'kafka' is already referencing to Kafka topic 'topic-test-internal' - // * spec.name: Invalid value: "topic-test-internal": topic "topic-test-internal" already exists on kafka cluster and it is not managed by Koperator, - // if you want it to be managed by Koperator so you can modify its configurations through a KafkaTopic CR, - // add this "managedBy: koperator" annotation to this KafkaTopic CR - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(5)) - Expect(err.Error()).To(And( - ContainSubstring("The KafkaTopic %q is invalid:", caseData["Name"]), - ContainSubstring("spec.name: Invalid value: %[1]q: kafkaTopic CR '%[1]s' in namesapce '%[2]s' is already referencing to Kafka topic '%[1]s'", - testInternalTopicName, kubectlOptions.Namespace), - ContainSubstring("spec.name: Invalid value: %[1]q: topic %[1]q already exists on kafka cluster and it is not managed by Koperator", - testInternalTopicName), - )) - }) - requireDeleteKafkaTopic(kubectlOptions, testInternalTopicName) - }) - }) -} - -func testWebhookUpdateKafkaTopic(kubectlOptions k8s.KubectlOptions, kafkaCluster types.NamespacedName) bool { - return When("Testing KafkaTopic Update", func() { - BeforeAll(func() { - Expect(isExistingK8SResource(kubectlOptions, kafkaKind, kafkaClusterName)).To(BeTrue()) - }) - - const nonExistent string = "non-existent" - - baseKafkaTopicTemplateValues := baseKafkaTopicData( - types.NamespacedName{Name: testInternalTopicName, Namespace: kubectlOptions.Namespace}, - kafkaCluster, - ) - - // Update operation implies having a CR with the same name in place - requireDeployingKafkaTopic(kubectlOptions, testInternalTopicName) - - It("Test non-existent KafkaCluster", func() { - caseData := copyMapWithStringKeys(baseKafkaTopicTemplateValues) - caseData["ClusterRef"] = map[string]string{ - "Name": nonExistent, - "Namespace": kafkaCluster.Namespace, - } - - err := applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal" is invalid: spec.clusterRef.name: Invalid value: "non-existent": kafkaCluster 'non-existent' in the namespace 'kafka' does not exist - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(1)) - Expect(err.Error()).To( - ContainSubstring("The KafkaTopic %[1]q is invalid: spec.clusterRef.name: Invalid value: %[2]q: kafkaCluster '%[2]s' in the namespace '%[3]s' does not exist", - caseData["Name"], nonExistent, kubectlOptions.Namespace), - ) - }) - - // A successfully created KafkaTopic CR cannot have 0 for either Partition or ReplicationFactor. - // At the same time, during an Update, a KafkaTopic cannot have its: - // * spec.partitions decreased - // * spec.replicationFactor changed (not just decreased) - // Consequently, an Update test for 0 values will automatically also cover the decreasing/changing scenarios. - It("Test 0 values partitions and replicationFactor", func() { - caseData := copyMapWithStringKeys(baseKafkaTopicTemplateValues) - caseData["Partitions"] = "0" - caseData["ReplicationFactor"] = "0" - err := applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal" is invalid: - // * spec.partitions: Invalid value: 0: number of partitions must be larger than 0 (or set it to be -1 to use the broker's default) - // * spec.replicationFactor: Invalid value: 0: replication factor must be larger than 0 (or set it to be -1 to use the broker's default) - // * spec.partitions: Invalid value: 0: kafka does not support decreasing partition count on an existing topic (from 2 to 0) - // * spec.replicationFactor: Invalid value: 0: kafka does not support changing the replication factor on an existing topic (from 2 to 0) - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(5)) - Expect(err.Error()).To(And( - ContainSubstring("The KafkaTopic %q is invalid:", caseData["Name"]), - ContainSubstring("spec.partitions: Invalid value: 0: number of partitions must be larger than 0"), - ContainSubstring("spec.replicationFactor: Invalid value: 0: replication factor must be larger than 0"), - ContainSubstring("spec.partitions: Invalid value: %s: kafka does not support decreasing partition count on an existing topic", caseData["Partitions"]), - ContainSubstring("spec.replicationFactor: Invalid value: %s: kafka does not support changing the replication factor on an existing topic", caseData["ReplicationFactor"]), - )) - }) - - It("Testing conflict on spec.name", func() { - caseData := copyMapWithStringKeys(baseKafkaTopicTemplateValues) - - switch v := caseData["Name"].(type) { - case string: - caseData["Name"] = v + "-different-cr-name" - case fmt.Stringer: - caseData["Name"] = v.String() + "-different-cr-name" - default: - caseData["Name"] = nonExistent - } - - By("With managedBy koperator annotation") - caseData["Annotations"] = []string{"managedBy: koperator"} - err := applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal-different-cr-name" is invalid: spec.name: Invalid value: "topic-test-internal": kafkaTopic CR 'topic-test-internal' in namesapce 'kafka' is already referencing to Kafka topic 'topic-test-internal' - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(1)) - Expect(err.Error()).To( - ContainSubstring("The KafkaTopic %[1]q is invalid: spec.name: Invalid value: %[2]q: kafkaTopic CR '%[2]s' in namesapce '%[3]s' is already referencing to Kafka topic '%[2]s'", - caseData["Name"], testInternalTopicName, kubectlOptions.Namespace), - ) - - By("Without managedBy koperator annotation") - caseData["Annotations"] = []string{} - err = applyK8sResourceFromTemplate( - kubectlOptions, - kafkaTopicTemplate, - caseData, - dryRunStrategyArgServer, - ) - Expect(err).To(HaveOccurred()) - // Example error: - // error while running command: exit status 1; The KafkaTopic "topic-test-internal-different-cr-name" is invalid: - // * spec.name: Invalid value: "topic-test-internal": kafkaTopic CR 'topic-test-internal' in namesapce 'kafka' is already referencing to Kafka topic 'topic-test-internal' - // * spec.name: Invalid value: "topic-test-internal": topic "topic-test-internal" already exists on kafka cluster and it is not managed by Koperator, - // if you want it to be managed by Koperator so you can modify its configurations through a KafkaTopic CR, - // add this "managedBy: koperator" annotation to this KafkaTopic CR - Expect(len(strings.Split(err.Error(), "\n"))).To(Equal(5)) - Expect(err.Error()).To(And( - ContainSubstring("The KafkaTopic %q is invalid:", caseData["Name"]), - ContainSubstring("spec.name: Invalid value: %[1]q: kafkaTopic CR '%[1]s' in namesapce '%[2]s' is already referencing to Kafka topic '%[1]s'\n", - testInternalTopicName, kubectlOptions.Namespace), - ContainSubstring("spec.name: Invalid value: %[1]q: topic %[1]q already exists on kafka cluster and it is not managed by Koperator", - testInternalTopicName), - )) - }) - - // Clean up the KafkaTopic set up to test Update operations against - requireDeleteKafkaTopic(kubectlOptions, testInternalTopicName) - }) -} - -func baseKafkaTopicData(kafkaTopic types.NamespacedName, kafkaCluster types.NamespacedName) map[string]interface{} { // string topic name first - return map[string]interface{}{ - "Name": kafkaTopic.Name, - "TopicName": kafkaTopic.Name, - "Namespace": kafkaTopic.Namespace, - "Partitions": "2", - "ReplicationFactor": "2", - "ClusterRef": map[string]string{ - "Name": kafkaCluster.Name, - "Namespace": kafkaCluster.Namespace, - }, - "Annotations": []string{"managedBy: koperator"}, - } -} - -func copyMapWithStringKeys(oldMap map[string]interface{}) map[string]interface{} { - var newMap = make(map[string]interface{}) - for k := range oldMap { - newMap[k] = oldMap[k] - } - return newMap -} diff --git a/tests/e2e/koperator_suite_test.go b/tests/e2e/koperator_suite_test.go index 57a9b15c7..72051b048 100644 --- a/tests/e2e/koperator_suite_test.go +++ b/tests/e2e/koperator_suite_test.go @@ -55,18 +55,18 @@ var _ = BeforeSuite(func() { }) var _ = When("Testing e2e test altogether", Ordered, func() { - // var snapshottedInfo = &clusterSnapshot{} - // snapshotCluster(snapshottedInfo) - // testInstall() - // testInstallZookeeperCluster() - // testInstallKafkaCluster("../../config/samples/simplekafkacluster.yaml") + var snapshottedInfo = &clusterSnapshot{} + snapshotCluster(snapshottedInfo) + testInstall() + testInstallZookeeperCluster() + testInstallKafkaCluster("../../config/samples/simplekafkacluster.yaml") testWebhookKafkaTopic(types.NamespacedName{Name: kafkaClusterName, Namespace: koperatorLocalHelmDescriptor.Namespace}) - // testProduceConsumeInternal() - // testUninstallKafkaCluster() - // testInstallKafkaCluster("../../config/samples/simplekafkacluster_ssl.yaml") - // testProduceConsumeInternalSSL(defaultTLSSecretName) - // testUninstallKafkaCluster() - // testUninstallZookeeperCluster() - // testUninstall() - // snapshotClusterAndCompare(snapshottedInfo) + testProduceConsumeInternal() + testUninstallKafkaCluster() + testInstallKafkaCluster("../../config/samples/simplekafkacluster_ssl.yaml") + testProduceConsumeInternalSSL(defaultTLSSecretName) + testUninstallKafkaCluster() + testUninstallZookeeperCluster() + testUninstall() + snapshotClusterAndCompare(snapshottedInfo) })