diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index a96131b84..7534e4e89 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -93,4 +93,10 @@ var _ = AfterSuite(func(ctx SpecContext) { _, _ = fmt.Fprintf(GinkgoWriter, "Uninstalling CertManager...\n") UninstallCertManager(ctx) } + + cwd, err := GetProjectDir() + Expect(err).NotTo(HaveOccurred(), "Failed to get project directory") + + err = CommentCode(cwd+"/config/default/kustomization.yaml", "- ../prometheus", "#") + Expect(err).NotTo(HaveOccurred(), "Failed to disable Prometheus") }) diff --git a/test/e2e/util_test.go b/test/e2e/util_test.go index 2f61ee028..fcdc4e264 100644 --- a/test/e2e/util_test.go +++ b/test/e2e/util_test.go @@ -319,6 +319,32 @@ func UncommentCode(filename, target, prefix string) error { return os.WriteFile(filename, out.Bytes(), 0o644) } +// CommentCode searches for target in the file and adds the comment prefix +// to each line of the target content. The target content may span multiple lines. +func CommentCode(filename, target, prefix string) error { + content, err := os.ReadFile(filename) + if err != nil { + return err + } + + before, after, ok := bytes.Cut(content, []byte(target)) + if !ok { + return fmt.Errorf("unable to find the code %s to be commented", target) + } + + out := new(bytes.Buffer) + out.Write(before) + for line := range strings.SplitAfterSeq(target, "\n") { + if line != "" { + out.WriteString(prefix) + out.WriteString(line) + } + } + out.Write(after) + + return os.WriteFile(filename, out.Bytes(), 0o644) +} + // GetNonEmptyLines converts given command output string into individual objects // according to line breakers, and ignores the empty elements in it. func GetNonEmptyLines(output string) []string {