Help us shape the future of Go! Take the 2026 Go Developer Survey

utils

package
v0.52.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package utils provides utility functions for e2e testing. This package contains helper functions for executing commands, managing Kubernetes resources, and handling common testing operations like installing/uninstalling operators and checking CRDs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNonEmptyLines

func GetNonEmptyLines(output string) []string

GetNonEmptyLines converts given command output string into individual objects according to line breakers, and ignores the empty elements in it. This function is useful for parsing command output that contains multiple lines.

Parameters:

  • output: The command output string to parse

Returns:

  • []string: A slice of non-empty lines from the output

func GetProjectDir

func GetProjectDir() (string, error)

GetProjectDir will return the directory where the project is located. It handles the case where the current working directory might be in a subdirectory like test/e2e and adjusts the path accordingly.

Returns:

  • string: The project root directory path
  • error: Any error that occurred while getting the working directory

func InstallCertManager

func InstallCertManager() error

InstallCertManager installs the cert-manager bundle. It downloads and applies the cert-manager bundle, then waits for the webhook to be ready. The webhook readiness check is important because cert-manager may be re-installed after uninstalling on a cluster.

Returns:

  • error: Any error that occurred during installation

func InstallPrometheusOperator

func InstallPrometheusOperator() error

InstallPrometheusOperator installs the Prometheus Operator to be used for exporting metrics. It downloads and applies the operator bundle from the official GitHub releases.

Returns:

  • error: Any error that occurred during installation

func IsCertManagerCRDsInstalled

func IsCertManagerCRDsInstalled() bool

IsCertManagerCRDsInstalled checks if any Cert Manager CRDs are installed by verifying the existence of key CRDs related to Cert Manager. This function is useful for determining if cert-manager is already installed.

Returns:

  • bool: True if any Cert Manager CRDs are found, false otherwise

func IsPrometheusCRDsInstalled

func IsPrometheusCRDsInstalled() bool

IsPrometheusCRDsInstalled checks if any Prometheus CRDs are installed by verifying the existence of key CRDs related to Prometheus. This function is useful for determining if Prometheus Operator is already installed.

Returns:

  • bool: True if any Prometheus CRDs are found, false otherwise

func LoadImageToKindClusterWithName

func LoadImageToKindClusterWithName(name string) error

LoadImageToKindClusterWithName loads a local docker image to the kind cluster. This function is useful for testing with custom images that aren't available in public registries. The cluster name can be overridden by setting the KIND_CLUSTER environment variable.

Parameters:

  • name: The name of the docker image to load

Returns:

  • error: Any error that occurred during image loading

func Run

func Run(cmd *exec.Cmd) (string, error)

Run executes the provided command within the project context. It sets up the working directory, environment variables, and captures both stdout and stderr. The function logs the command being executed and returns the combined output.

Parameters:

  • cmd: The command to execute

Returns:

  • string: The combined stdout and stderr output
  • error: Any error that occurred during command execution

func RunWithInput added in v0.5.0

func RunWithInput(cmd *exec.Cmd, input string) (string, error)

RunWithInput executes the provided command with input from stdin. This is useful for commands like `kubectl apply -f -` that expect YAML input.

Parameters:

  • cmd: The command to execute
  • input: The input string to provide via stdin

Returns:

  • string: The combined stdout and stderr output
  • error: Any error that occurred during command execution

func UncommentCode

func UncommentCode(filename, target, prefix string) error

UncommentCode searches for target in the file and removes the comment prefix of the target content. The target content may span multiple lines. This function is useful for programmatically enabling features in configuration files.

Parameters:

  • filename: The path to the file to modify
  • target: The target content to uncomment
  • prefix: The comment prefix to remove (e.g., "// " or "# ")

Returns:

  • error: Any error that occurred during file modification

func UninstallCertManager

func UninstallCertManager()

UninstallCertManager uninstalls the cert-manager bundle. It removes the cert-manager that was previously installed. Errors during uninstallation are logged as warnings since they're not critical.

func UninstallPrometheusOperator

func UninstallPrometheusOperator()

UninstallPrometheusOperator uninstalls the Prometheus Operator. It removes the operator bundle that was previously installed. Errors during uninstallation are logged as warnings since they're not critical.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL