cmdtest

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 13 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 runs a command group against a fake API in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Method      string
	Path        string // path plus raw query
	ContentType string
	Raw         []byte
	Body        interface{} // decoded JSON body, nil when empty or not JSON
}

Request is one call the command sent.

func Last

func Last(reqs []Request) Request

Last returns the last request, or a zero Request.

func Run

func Run(t *testing.T, group *cobra.Command, respond Responder, args ...string) (string, []Request, error)

Run executes `<group> <args...>` against a fake API and returns what it printed to stdout and the requests it sent.

func (Request) Obj

func (r Request) Obj() map[string]interface{}

Obj returns the body as a JSON object.

type Responder

type Responder func(method, path string) (status int, body string)

Responder answers a request; returning "" answers {"detail":"ok"}.

Jump to

Keyboard shortcuts

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