Documentation
¶
Overview ¶
Package apitest boots GoRun for API tests and drives /api/v1 with a bearer API key. It is importable by any module's tests whose module comes after "api" in kernel.BootOrder (the import-order test also covers _test.go files).
Set kernel.LogOutput = io.Discard in TestMain to keep test output clean.
Index ¶
- func Boot(t testing.TB, mods ...kernel.Module) *kernel.App
- func Data(body map[string]any) map[string]any
- func ErrorCode(body map[string]any) string
- func URL(path string) string
- type Client
- func (c *Client) Anonymous() *Client
- func (c *Client) Delete(path string, body any) (status int, resp map[string]any)
- func (c *Client) Do(method, path string, body any, header http.Header) *httptest.ResponseRecorder
- func (c *Client) Get(path string) (status int, body map[string]any)
- func (c *Client) Patch(path string, body any) (status int, resp map[string]any)
- func (c *Client) Post(path string, body any) (status int, resp map[string]any)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Boot ¶
Boot boots GoRun on a temp data dir with the settings and auth modules followed by mods. Unless mods already contains a module named "api", the api module is inserted before the first module that comes after "api" in kernel.BootOrder (or appended). The app is closed when t ends.
Types ¶
type Client ¶
type Client struct {
Token string // plaintext bearer key
User *auth.User // key owner
Key *auth.APIKey // the key
// contains filtered or unexported fields
}
Client calls the API of a booted app with a bearer key.
func NewClient ¶
NewClient returns a client whose key belongs to a fresh admin user and carries scopes (default "*").
func (*Client) Do ¶
Do sends a request with the bearer key (body: nil, []byte/string sent raw, anything else JSON-encoded) and returns the recorded response.
type Options ¶
type Options struct {
Role string // owner role, default "admin"
Scopes []string // key scopes, default ["*"]
RatePerMin int // key rate limit, default 100000 (effectively unlimited)
Kind string // auth.KeyKindAPI (default) or auth.KeyKindAgent
User *auth.User // existing key owner; nil creates a fresh user with Role
}
Options configure New.