testenv

package
v0.0.0-...-112a848 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testenv builds a hermetic *env.Env for command tests: an httptest server, an in-memory credential store, a temp config dir and captured stdout/stderr.

Index

Constants

View Source
const ContextName = "test"

ContextName is the name of the context the harness creates and selects.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	Env    *env.Env
	Server *httptest.Server
	Store  *secret.Memory
	Out    *bytes.Buffer
	Err    *bytes.Buffer
	Stdin  *strings.Reader
	Now    time.Time
}

Harness bundles the fake world a command runs in.

func New

func New(t *testing.T, handler http.Handler, creds map[string]string, stdin string) *Harness

New starts handler on an httptest server, selects a context pointing at it and stores creds (kind -> value, kinds are secret.Kind*). Output defaults to json. stdin is what the command reads on its standard input.

func (*Harness) Run

func (h *Harness) Run(cmd *cobra.Command, args ...string) error

Run executes cmd with args, returning its error. Output is in h.Out / h.Err.

Jump to

Keyboard shortcuts

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