test

package
v1.4.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Prefix = "/api"

Prefix is the path prefix for the API routes

Variables

This section is empty.

Functions

func Begin

func Begin(t *testing.T) (*pgqueue.Manager, context.Context)

Begin returns the shared test manager and a per-test context.

func End

func End(t *testing.T)

End releases the per-test context created by Begin.

func IsolatedManager added in v1.4.0

func IsolatedManager(t *testing.T, opts ...pgqueue.Opt) *pgqueue.Manager

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.

func Main

func Main(m *testing.M, setup func(*pgqueue.Manager) (func(), error), opts ...pgqueue.Opt)

Main initializes a PostgreSQL pool and manager before running the tests, and runs the manager's event loop while they run. If PGQUEUE_TEST_DATABASE_URL is set, it connects to that server; otherwise it starts a PostgreSQL container.

func Schema added in v1.4.0

func Schema() string

Schema returns the database schema used by the shared test manager, for tests which need to refer to its tables directly

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

func (Exchange) String added in v1.4.0

func (e Exchange) String() string

type Server added in v1.4.0

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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

func NewServer(t *testing.T, manager *pgqueue.Manager) *Server

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

func NewServerFunc(t *testing.T, register func(*httprouter.Router) error) *Server

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

func (s *Server) Do(t *testing.T, method, path string, body any) (int, []byte)

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) Exchanges added in v1.4.0

func (s *Server) Exchanges() []Exchange

Exchanges returns the recorded requests and responses

func (*Server) JSON added in v1.4.0

func (s *Server) JSON(t *testing.T, method, path string, body, v any) int

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

func (*Server) Spec added in v1.4.0

func (s *Server) Spec() *openapi.Spec

Spec returns the OpenAPI specification for the API

func (*Server) Verify added in v1.4.0

func (s *Server) Verify() []error

Verify checks every recorded exchange against the OpenAPI specification, and returns an error for each which does not conform

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL