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

testshell

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HelmClient

type HelmClient struct {
	// DockerConfig is the value to use for DOCKER_CONFIG.
	// Crane uses DOCKER_CONFIG for auth settings.
	// Helm uses DOCKER_CONFIG for default auth settings, when not specified in
	// HELM_REGISTRY_CONFIG.
	DockerConfig string

	// ConfigHome is the value to use for HELM_CONFIG_HOME.
	//
	// Defaults:
	// - Linux: ${HOME}/.config/helm
	// - Mac: ${HOME}/Library/Preferences/helm
	//   https://github.com/helm/helm/blob/main/pkg/helmpath/lazypath_darwin.go#L28
	// - Windows: ${APPDATA}/helm
	//   https://github.com/helm/helm/blob/main/pkg/helmpath/lazypath_windows.go#L22
	//
	// Affects default values for HELM_REGISTRY_CONFIG, HELM_REPOSITORY_CONFIG
	// HELM_REPOSITORY_CACHE, and HELM_CACHE_HOME.
	ConfigHome string

	// Shell used to execute helm and crane client commands.
	Shell *TestShell
}

HelmClient provides helm and crane clients for connecting to an Helm repository.

func NewHelmClient

func NewHelmClient(parentPath string, shell *TestShell) *HelmClient

NewHelmClient constructs a new HelmClient that stores config in sub-directories under the specified `parentPath`.

func (*HelmClient) Crane

func (hc *HelmClient) Crane(args ...string) ([]byte, error)

Crane executes a crane command with the HelmClient's config.

func (*HelmClient) Helm

func (hc *HelmClient) Helm(args ...string) ([]byte, error)

Helm executes a helm command with the HelmClient's config.

func (*HelmClient) Login

func (hc *HelmClient) Login(registryHost string) error

Login uses gcloud to configure docker auth credentials used by helm and crane.

Files modified: - `${DOCKER_CONFIG}/config.json` (crane/docker)

func (*HelmClient) Logout

func (hc *HelmClient) Logout(registryHost string) error

Logout removes credentials for the specified registry.

Files modified: - `${DOCKER_CONFIG}/config.json` (crane/docker) - `${HELM_CONFIG_HOME}/registry/config.json` (helm)

type OCIClient

type OCIClient struct {
	// DockerConfig is the value to use for DOCKER_CONFIG.
	// Crane uses DOCKER_CONFIG for auth settings.
	DockerConfig string

	// Shell used to execute crane client commands.
	Shell *TestShell
}

OCIClient provides a crane client for connecting to an OCI repository.

func NewOCIClient

func NewOCIClient(parentPath string, shell *TestShell) *OCIClient

NewOCIClient constructs a new OCIClient that stores config in sub-directories under the specified `parentPath`.

func (*OCIClient) Crane

func (oc *OCIClient) Crane(args ...string) ([]byte, error)

Crane executes a crane command with the OCIClient's config.

func (*OCIClient) Login

func (oc *OCIClient) Login(registryHost string) error

Login uses gcloud to configure docker auth credentials used by crane.

Files modified: - `${DOCKER_CONFIG}/config.json` (crane/docker)

func (*OCIClient) Logout

func (oc *OCIClient) Logout(registryHost string) error

Logout removes credentials for the specified registry.

Files modified: - `${DOCKER_CONFIG}/config.json` (crane/docker)

type TestShell

type TestShell struct {
	// Context to use, if not specified by the method.
	Context context.Context

	// Env to use for all commands, if non-nil.
	// Default: os.Environ()
	Env []string

	// Logger for methods to use.
	Logger *testlogger.TestLogger
}

TestShell is a helper utility to execute shell commands in a test. Handles logging and injection of the KUBECONFIG as argument or env var.

func (*TestShell) Command

func (tc *TestShell) Command(name string, args ...string) *exec.Cmd

Command is a convenience method for invoking a subprocess with the KUBECONFIG environment variable set. Setting the environment variable directly in the test process is not thread safe.

func (*TestShell) ExecWithDebug

func (tc *TestShell) ExecWithDebug(name string, args ...string) ([]byte, error)

ExecWithDebug is a convenience method for invoking a subprocess with the KUBECONFIG environment variable and debug logging.

func (*TestShell) ExecWithDebugEnv

func (tc *TestShell) ExecWithDebugEnv(name string, envVars map[string]string, args ...string) ([]byte, error)

ExecWithDebugEnv is similar to ExecWithDebug but allows passing additional environment variables for the command execution.

func (*TestShell) Gcloud

func (tc *TestShell) Gcloud(args ...string) ([]byte, error)

Gcloud is a convenience method for calling gcloud against the currently-connected cluster. Returns STDOUT/STDERR, and an error if gcloud exited abnormally.

If you want to fail the test immediately on failure, wrap with nt.Must.

func (*TestShell) Kubectl

func (tc *TestShell) Kubectl(args ...string) ([]byte, error)

Kubectl is a convenience method for calling kubectl against the currently-connected cluster. Returns STDOUT, and an error if kubectl exited abnormally.

If you want to fail the test immediately on failure, use MustKubectl.

func (*TestShell) KubectlContext

func (tc *TestShell) KubectlContext(ctx context.Context, args ...string) ([]byte, error)

KubectlContext is similar to TestShell.Kubectl but allows using a context to cancel (kill signal) the kubectl command.

Jump to

Keyboard shortcuts

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