Documentation
¶
Index ¶
- Constants
- func Begin(t *testing.T) (*pgqueue.Manager, context.Context)
- func End(t *testing.T)
- func IsolatedManager(t *testing.T, opts ...pgqueue.Opt) *pgqueue.Manager
- func Main(m *testing.M, setup func(*pgqueue.Manager) (func(), error), ...)
- func Schema() string
- type Exchange
- type Server
- func (s *Server) Do(t *testing.T, method, path string, body any) (int, []byte)
- func (s *Server) DoWithContentType(t *testing.T, method, path, contentType string, body any) (int, []byte)
- func (s *Server) Exchanges() []Exchange
- func (s *Server) JSON(t *testing.T, method, path string, body, v any) int
- func (s *Server) Reset()
- func (s *Server) Spec() *openapi.Spec
- func (s *Server) Verify() []error
Constants ¶
const Prefix = "/api"
Prefix is the path prefix for the API routes
Variables ¶
This section is empty.
Functions ¶
func IsolatedManager ¶ added in v1.4.0
IsolatedManager returns a new manager on a new, empty database schema, so that a test can make assertions about every object, which it cannot do with the shared manager as other tests also create objects. The manager's event loop is not run.
Types ¶
type Exchange ¶ added in v1.4.0
type Exchange struct {
Method string
Path string
// Pattern is the route pattern which matched the request, such as
// "/api/queue", or empty if no route matched
Pattern string
RequestHeader http.Header
RequestBody []byte
Status int
ResponseHeader http.Header
ResponseBody []byte
}
Exchange is a recorded request and response
type Server ¶ added in v1.4.0
Server is a HTTP test server serving the pgqueue API. Every request and response is recorded, and checked against the OpenAPI specification when the test ends.
func NewServer ¶ added in v1.4.0
NewServer starts a HTTP test server serving the pgqueue API for the manager. When the test ends the server is closed, and every recorded exchange is checked against the OpenAPI specification.
func NewServerFunc ¶ added in v1.4.0
NewServerFunc starts a HTTP test server serving the API registered by the function. When the test ends the server is closed, and every recorded exchange is checked against the OpenAPI specification.
func (*Server) Do ¶ added in v1.4.0
Do sends a request to the API with a JSON body, and returns the status code and response body. The path is relative to the API prefix, and may include a query string. A body which is a string or []byte is sent as-is, nil sends no body, and any other value is encoded as JSON.
func (*Server) DoWithContentType ¶ added in v1.4.0
func (s *Server) DoWithContentType(t *testing.T, method, path, contentType string, body any) (int, []byte)
DoWithContentType sends a request with the body as the content type, which is used as-is for a string or []byte body, and otherwise encoded as JSON. Returns the status code and the response body.
func (*Server) JSON ¶ added in v1.4.0
JSON sends a request to the API as Do does, and decodes a successful response body into v. Returns the status code.
func (*Server) Reset ¶ added in v1.4.0
func (s *Server) Reset()
Reset discards the recorded requests and responses