Documentation
¶
Overview ¶
Package apptest runs the whole HTTP stack against a fresh test database so API behaviour can be tested end to end: middleware, authz, handlers, SQL.
Index ¶
- type Client
- func (c *Client) Do(method, path string, body any) *Response
- func (c *Client) DoRaw(method, path, contentType string, body io.Reader) *Response
- func (c *Client) SignIn(email, password string)
- func (c *Client) SignInDemo(email string)
- func (c *Client) Stream(ctx context.Context, path string) (*http.Response, error)
- type Env
- type Response
- type SMTPSink
- type SinkMessage
- type UserOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Bearer is sent as Authorization when set (API keys, agents).
Bearer string
// Header is added to every request (Accept-Language…).
Header http.Header
// contains filtered or unexported fields
}
Client is a browser-like client with its own cookie jar.
func (*Client) DoRaw ¶
DoRaw sends a request with a raw body and content type (multipart uploads) to path under /api/v1, or to a non-API path as is ("/media/…").
func (*Client) SignInDemo ¶
SignInDemo signs in as a demo user. Demo users with an authenticator get a session directly (tests don't type TOTP codes).
type Env ¶
Env is a running test instance.
func (*Env) CreateUser ¶
CreateUser inserts a user directly.
func (*Env) CreateWorkspace ¶
CreateWorkspace creates a workspace owned by owner.
func (*Env) SeedDemo ¶
func (e *Env) SeedDemo()
SeedDemo loads the Acme demo data into the test database.
func (*Env) SeedNorthwind ¶
func (e *Env) SeedNorthwind()
SeedNorthwind loads the agency sample (Northwind Studio and its seven clients) into the test database instead of the Acme demo.
type Response ¶
Response is a decoded API response.
func (*Response) MustStatus ¶
MustStatus fails the test unless the response has the given status.
type SMTPSink ¶
type SMTPSink struct {
Addr string
// Reject makes AUTH fail with 535.
Reject bool
// contains filtered or unexported fields
}
SMTPSink is a minimal SMTP server for tests: it accepts EHLO, AUTH PLAIN or LOGIN (any credentials unless Reject is set), MAIL, RCPT and DATA, and keeps every message it received.
func NewSMTPSink ¶
NewSMTPSink starts a sink on a free local port; it stops with the test.
func (*SMTPSink) Messages ¶
func (s *SMTPSink) Messages() []SinkMessage
Messages returns what the sink received so far.
type SinkMessage ¶
SinkMessage is one message the sink received.