cmdtest

package
v0.4.0-beta Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MPL-2.0 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 cmdtest provides shared test helpers for command tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInvocation

func NewInvocation(t *testing.T, io *iostreams.Testing, server *httptest.Server) *cmd.Invocation

NewInvocation creates a cmd.Invocation suitable for testing, with a profile pointed at the given test server.

func NewServer

func NewServer(t *testing.T, routes RouteMap) *httptest.Server

NewServer creates an httptest.Server with the given routes and registers cleanup.

func WriteJSONAPI

func WriteJSONAPI(w http.ResponseWriter, payload any)

WriteJSONAPI writes a JSON:API response with the correct content type.

Types

type RouteMap

type RouteMap map[string]http.HandlerFunc

RouteMap maps "METHOD /path" to a handler function for use in test servers.

func (RouteMap) ServeHTTP

func (rm RouteMap) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches to the matching route handler. It tries an exact match including query params first, then falls back to path-only matching.

Jump to

Keyboard shortcuts

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