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 ¶
- func MidMonth() time.Time
- 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
- func (e *Env) AddMember(ws store.Workspace, user uuid.UUID, roleKey string)
- func (e *Env) Client() *Client
- func (e *Env) CreateUser(o UserOpts) store.User
- func (e *Env) CreateWorkspace(name string, owner uuid.UUID) store.Workspace
- func (e *Env) SeedDemo()
- func (e *Env) SeedDemoAt(at time.Time)
- func (e *Env) SeedNorthwind()
- type Response
- type SMTPSink
- type SinkMessage
- type UserOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MidMonth ¶
MidMonth is a moment in the past when the sample's design days (the 1st to the 15th of a month, "today" the 15th) fit in one calendar month: the 20th of last month at noon in New York. A test whose numbers count "this month" (the SMS spend) seeds there with SeedDemoAt, so it holds on any day of the month.
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) SeedDemoAt ¶
SeedDemoAt loads the Acme demo as seeded at a given moment and runs the app's clock (App.Now) from there, so the services that read it see the sample's days where they were seeded.
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.