Documentation
¶
Overview ¶
Package apptest provides small helpers for exercising a gin-kit application in tests and decoding its envelope responses. Assertions beyond status checks stay in plain Go.
Index ¶
- func Migrate(t *testing.T, connection *database.Connection, dialect database.Dialect, ...)
- func OpenSQLite(t *testing.T, orm database.ORM) *database.Connection
- func SQLiteConfig(t *testing.T, orm database.ORM) database.Config
- func Seed(t *testing.T, connection *database.Connection, ...)
- type App
- func (a *App) Application() *runtime.Application
- func (a *App) Client() *Client
- func (a *App) DELETE(path string, opts ...RequestOption) *Response
- func (a *App) Do(method, path string, body any, opts ...RequestOption) *Response
- func (a *App) GET(path string, opts ...RequestOption) *Response
- func (a *App) PATCH(path string, body any, opts ...RequestOption) *Response
- func (a *App) POST(path string, body any, opts ...RequestOption) *Response
- func (a *App) PUT(path string, body any, opts ...RequestOption) *Response
- func (a *App) Router() *gin.Engine
- type Client
- func (c *Client) CSRFToken(path string) string
- func (c *Client) DELETE(path string, opts ...RequestOption) *Response
- func (c *Client) Do(method, path string, body any, opts ...RequestOption) *Response
- func (c *Client) GET(path string, opts ...RequestOption) *Response
- func (c *Client) PATCH(path string, body any, opts ...RequestOption) *Response
- func (c *Client) POST(path string, body any, opts ...RequestOption) *Response
- func (c *Client) PUT(path string, body any, opts ...RequestOption) *Response
- type Form
- type MultipartBody
- type Raw
- type RequestOption
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenSQLite ¶
OpenSQLite opens a unique in-memory SQLite connection for integration tests. One connection is pinned for the test's lifetime so pool churn cannot drop the shared-cache database, and everything closes via t.Cleanup. The test is skipped when the SQLite driver is unavailable (CGO disabled).
func SQLiteConfig ¶
SQLiteConfig returns a database configuration for a unique in-memory SQLite database (shared cache, so every pooled connection sees the same data).
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App wraps a runtime application for in-process HTTP testing.
func New ¶
New builds an application from options, fails the test on error, and closes the application (shutdown hooks) when the test finishes.
func (*App) Application ¶
func (a *App) Application() *runtime.Application
Application exposes the wrapped runtime application.
func (*App) Client ¶
Client returns a stateful client that carries cookies across requests, for session and CSRF flows.
func (*App) DELETE ¶
func (a *App) DELETE(path string, opts ...RequestOption) *Response
DELETE performs this package operation.
func (*App) Do ¶
func (a *App) Do(method, path string, body any, opts ...RequestOption) *Response
Do performs an in-process request. Bodies: nil sends none, Form is form-urlencoded, *MultipartBody is multipart, Raw is sent verbatim, and anything else is JSON-encoded.
func (*App) GET ¶
func (a *App) GET(path string, opts ...RequestOption) *Response
GET performs this package operation.
func (*App) PATCH ¶
func (a *App) PATCH(path string, body any, opts ...RequestOption) *Response
PATCH performs this package operation.
func (*App) POST ¶
func (a *App) POST(path string, body any, opts ...RequestOption) *Response
POST performs this package operation.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client performs requests while persisting cookies between them.
func (*Client) CSRFToken ¶
CSRFToken GETs path with this client (establishing the session cookie) and extracts the CSRF token from the rendered hidden form field.
func (*Client) DELETE ¶
func (c *Client) DELETE(path string, opts ...RequestOption) *Response
DELETE performs this package operation.
func (*Client) Do ¶
func (c *Client) Do(method, path string, body any, opts ...RequestOption) *Response
Do performs this package operation.
func (*Client) GET ¶
func (c *Client) GET(path string, opts ...RequestOption) *Response
GET performs this package operation.
func (*Client) PATCH ¶
func (c *Client) PATCH(path string, body any, opts ...RequestOption) *Response
PATCH performs this package operation.
type MultipartBody ¶
type MultipartBody struct {
// contains filtered or unexported fields
}
MultipartBody builds a multipart/form-data request body.
func NewMultipart ¶
func NewMultipart() *MultipartBody
NewMultipart performs this package operation.
func (*MultipartBody) Field ¶
func (m *MultipartBody) Field(name, value string) *MultipartBody
Field performs this package operation.
func (*MultipartBody) File ¶
func (m *MultipartBody) File(field, filename, contentType string, content []byte) *MultipartBody
File performs this package operation.
type Raw ¶
type Raw struct {
// ContentType store data used by this type.
ContentType string
// Body store data used by this type.
Body []byte
}
Raw sends the body verbatim with the given content type.
type RequestOption ¶
RequestOption customizes one outgoing request.
func WithBearer ¶
func WithBearer(token string) RequestOption
WithBearer sets the Authorization header with a Bearer token.
func WithCookie ¶
func WithCookie(cookie *http.Cookie) RequestOption
WithCookie attaches a cookie to the request.
type Response ¶
type Response struct {
*httptest.ResponseRecorder
// contains filtered or unexported fields
}
Response wraps a recorded response with envelope decoding helpers.
func (*Response) RequireStatus ¶
RequireStatus fails the test unless the response has the given status.