cmdtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

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