Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit e0282d3

Browse files
update testcase logic; use local kafkatopic struct; use local tempfile function
1 parent b3bd748 commit e0282d3

File tree

4 files changed

+30
-357
lines changed

4 files changed

+30
-357
lines changed

tests/e2e/k8s.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,9 @@ func applyK8sResourceManifest(kubectlOptions k8s.KubectlOptions, manifestPath st
6565
// applyK8sResourceManifestFromString applies the specified manifest in string format to the provided
6666
// kubectl context and namespace.
6767
func applyK8sResourceManifestFromString(kubectlOptions k8s.KubectlOptions, manifest string, extraArgs ...string) error {
68-
// Replicating terratest's k8s.KubectlApplyFromStringE but with the possibility of a variadic argument that allows options like --dry-run
69-
//
70-
// TODO: look for a different implementation for temp files because terratest's version uses the composite test name to generate
71-
// the temp file name which, in our case, includes all the descriptive Ginkgo statements (which are by design quite verbose).
72-
// That can lead to erroring out on temp file creation based on the file name being too long.
73-
tmpfile, err := k8s.StoreConfigToTempFileE(GinkgoT(), manifest)
68+
tmpfile, err := createTempFileFromBytes([]byte(manifest), "", "", 0)
7469
if err != nil {
75-
return err
70+
return fmt.Errorf("storing provided manifest data into temp file failed: %w", err)
7671
}
7772
defer os.Remove(tmpfile)
7873

@@ -81,7 +76,7 @@ func applyK8sResourceManifestFromString(kubectlOptions k8s.KubectlOptions, manif
8176

8277
// applyK8sResourceFromTemplate generates manifest from the specified go-template based on values
8378
// and applies the specified manifest to the provided kubectl context and namespace.
84-
func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFile string, values map[string]any, extraArgs ...string) error {
79+
func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFile string, values any, extraArgs ...string) error {
8580
By(fmt.Sprintf("Generating k8s manifest from template %s", templateFile))
8681
var manifest bytes.Buffer
8782
rawTemplate, err := os.ReadFile(templateFile)
@@ -93,24 +88,7 @@ func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFil
9388
if err != nil {
9489
return err
9590
}
96-
return applyK8sResourceManifestFromString(kubectlOptions, manifest.String(), extraArgs...)
97-
}
9891

99-
// applyK8sResourceFromTemplate generates manifest from the specified go-template based on values
100-
// and applies the specified manifest to the provided kubectl context and namespace.
101-
func applyK8sResourceFromTemplate_2(kubectlOptions k8s.KubectlOptions, templateFile string, values any, extraArgs ...string) error {
102-
By(fmt.Sprintf("Generating k8s manifest from template %s", templateFile))
103-
var manifest bytes.Buffer
104-
rawTemplate, err := os.ReadFile(templateFile)
105-
if err != nil {
106-
return err
107-
}
108-
t := template.Must(template.New("template").Funcs(sprig.TxtFuncMap()).Parse(string(rawTemplate)))
109-
err = t.Execute(&manifest, values)
110-
if err != nil {
111-
return err
112-
}
113-
fmt.Printf("###\nManifest is :\n%s\n###\n", manifest.String())
11492
return applyK8sResourceManifestFromString(kubectlOptions, manifest.String(), extraArgs...)
11593
}
11694

tests/e2e/kafka.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ func requireDeleteKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName string
3535
// requireDeployingKafkaTopic deploys a kafkaTopic resource from a template
3636
func requireDeployingKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName string) {
3737
It("Deploying KafkaTopic CR", func() {
38-
// err := applyK8sResourceFromTemplate(kubectlOptions,
39-
// kafkaTopicTemplate,
40-
// map[string]interface{}{
41-
// "Name": topicName,
42-
// "TopicName": topicName,
43-
// "Namespace": kubectlOptions.Namespace,
44-
// },
45-
// )
4638
values := kafkaTopicTemplateData{
4739
Annotations: []string{"managedBy: koperator"},
4840
ClusterRef: kafkaTopicClusterRef{
@@ -56,7 +48,7 @@ func requireDeployingKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName str
5648
TopicName: topicName,
5749
}
5850

59-
err := applyK8sResourceFromTemplate_2(kubectlOptions, kafkaTopicTemplate, values)
51+
err := applyK8sResourceFromTemplate(kubectlOptions, kafkaTopicTemplate, values)
6052

6153
Expect(err).ShouldNot(HaveOccurred())
6254

0 commit comments

Comments
 (0)