Documentation
¶
Overview ¶
Package cmdtest runs a leaf command in process against a test server, as cmd.Execute would. It sits apart from pkg/testutil, which client's own tests import, because it builds a client.
Index ¶
- Variables
- func ClientFactory(ts *httptest.Server) func() (*client.AlpaconClient, error)
- func NoClient() (*client.AlpaconClient, error)
- func Run(cmd *cobra.Command, args ...string) (failure string, code int)
- func RunCaptured(build Build, args ...string) (stdout, stderr string, code int)
- func RunJSON(build Build, args ...string) (stdout, stderr string, code int)
- type Build
- type Fake
- type Reply
Constants ¶
This section is empty.
Variables ¶
var ErrNoLogin = errors.New("not logged in")
ErrNoLogin is what NoClient fails with.
Functions ¶
func ClientFactory ¶
func ClientFactory(ts *httptest.Server) func() (*client.AlpaconClient, error)
ClientFactory returns a client factory aimed at ts, so a test needs no login in HOME.
func NoClient ¶
func NoClient() (*client.AlpaconClient, error)
NoClient fails as a missing login does.
func Run ¶
Run executes cmd with args and returns the failure cmd.Execute would print and its exit code. It captures nothing else, so it is safe under t.Parallel.
func RunCaptured ¶
RunCaptured runs the command build returns on test streams and returns what it wrote to each; the failure is appended to stderr. It swaps nothing, so it is safe under t.Parallel.
Types ¶
type Fake ¶
Fake is a test server that answers fixed routes and counts the requests each one got.
func Server ¶
Server answers each "METHOD /path" key of routes with its Reply, ignoring the query string, and fails the test on any other request.