Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
26 changes: 26 additions & 0 deletions test/e2e/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading