Documentation
¶
Overview ¶
Package cmdtest provides shared test helpers for CLI command tests.
Index ¶
- func Error(w http.ResponseWriter, status int, message string)
- func ExtractID(path, prefix string) string
- func JSON(w http.ResponseWriter, v any)
- func JSONStatus(w http.ResponseWriter, status int, v any)
- func RunCmd(t *testing.T, args ...string)
- func RunCmdExpectErr(t *testing.T, want string, args ...string)
- func RunCmdWithFactory(t *testing.T, f *cmdutil.Factory, args ...string)
- func RunCmdWithFactoryExpectErr(t *testing.T, f *cmdutil.Factory, want string, args ...string)
- func Text(w http.ResponseWriter, s string)
- type TestServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, status int, message string)
Error writes an API error response.
func JSONStatus ¶
func JSONStatus(w http.ResponseWriter, status int, v any)
JSONStatus writes a JSON response with specified status code.
func RunCmdExpectErr ¶
RunCmdExpectErr executes a CLI command and asserts an error containing want.
func RunCmdWithFactory ¶
RunCmdWithFactory executes a CLI command using a specific factory and asserts no error.
func RunCmdWithFactoryExpectErr ¶
RunCmdWithFactoryExpectErr executes a CLI command using a specific factory and asserts an error containing want.
Types ¶
type TestServer ¶
type TestServer struct {
*httptest.Server
Factory *cmdutil.Factory
// contains filtered or unexported fields
}
TestServer wraps httptest.Server for easy API testing.
func NewTestServer ¶
func NewTestServer(t *testing.T) *TestServer
NewTestServer creates a test server and configures a Factory with a mock client.
func SetupMockClient ¶
func SetupMockClient(t *testing.T) *TestServer
SetupMockClient creates a test server with all common API endpoints pre-registered.
func (*TestServer) CloneFactory ¶
func (ts *TestServer) CloneFactory() *cmdutil.Factory
CloneFactory returns a new Factory that shares the same ClientFunc and IOStreams but has its own flag storage, making it safe for parallel subtests.
func (*TestServer) Handle ¶
func (ts *TestServer) Handle(pattern string, h http.HandlerFunc)
Handle registers a handler for "METHOD /path" pattern.