Documentation
¶
Overview ¶
Package testutils provides utilities for use in tests
Index ¶
- Variables
- func AssertBodyString(t *testing.T, rc io.ReadCloser, expected string)
- func AssertFailureNotCalled(t *testing.T) http.Handler
- func AssertSuccessNotCalled(t *testing.T) http.Handler
- func CreateSessionManager() sessions.Store[map[string]any]
- func CreateTokenManager(refreshOverlap time.Duration) (*tokens.TokenManager, error)
- func NewErrorServer(message string, code int) (*http.Client, *httptest.Server)
- func NewRedisClient() *redis.Client
- func NewTestServerFunc(handler func(w http.ResponseWriter, r *http.Request)) *httptest.Server
- func TeardownFixture(tf *TestFixture)
- func TestServer() (*http.Client, *http.ServeMux, *httptest.Server)
- type RewriteTransport
- type TestFixture
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidDBURI is returned when an invalid DB URI is used ErrInvalidDBURI = errors.New("invalid DB URI") )
Functions ¶
func AssertBodyString ¶
func AssertBodyString(t *testing.T, rc io.ReadCloser, expected string)
AssertBodyString asserts that a Request Body matches the expected string
func AssertFailureNotCalled ¶
AssertFailureNotCalled is a failure http.Handler that fails if called
func AssertSuccessNotCalled ¶
AssertSuccessNotCalled is a success http.Handler that fails if called
func CreateSessionManager ¶
CreateSessionManager creates a new session manager for testing
func CreateTokenManager ¶
func CreateTokenManager(refreshOverlap time.Duration) (*tokens.TokenManager, error)
CreateTokenManager creates a new token manager for testing
func NewErrorServer ¶
NewErrorServer returns a new httptest.Server, which responds with the given error message and code and a client which proxies requests to the server
func NewRedisClient ¶
func NewRedisClient() *redis.Client
NewRedisClient creates a new redis client for testing using miniredis
func NewTestServerFunc ¶
NewTestServerFunc is an adapter to allow the use of ordinary functions
func TeardownFixture ¶
func TeardownFixture(tf *TestFixture)
Types ¶
type RewriteTransport ¶
type RewriteTransport struct {
Transport http.RoundTripper
}
RewriteTransport rewrites https requests to http to avoid TLS tomfoolery
type TestFixture ¶
type TestFixture struct { Pool *dockertest.Pool URI string Dialect string // contains filtered or unexported fields }
func GetPostgresDockerTest ¶
func GetPostgresDockerTest(image string, expiry time.Duration) (*TestFixture, error)
func GetTestURI ¶
func GetTestURI(u string, expiryMinutes int) *TestFixture
GetTestURI returns the dialect, connection string and if used a testcontainer for database connectivity in tests