testutils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package testutils provides utilities for use in tests

Index

Constants

This section is empty.

Variables

View Source
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

func AssertFailureNotCalled(t *testing.T) http.Handler

AssertFailureNotCalled is a failure http.Handler that fails if called

func AssertSuccessNotCalled

func AssertSuccessNotCalled(t *testing.T) http.Handler

AssertSuccessNotCalled is a success http.Handler that fails if called

func NewErrorServer

func NewErrorServer(message string, code int) (*http.Client, *httptest.Server)

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 NewTestServerFunc

func NewTestServerFunc(handler func(w http.ResponseWriter, r *http.Request)) *httptest.Server

NewTestServerFunc is an adapter to allow the use of ordinary functions

func TeardownFixture

func TeardownFixture(tf *TestFixture)

func TestServer

func TestServer() (*http.Client, *http.ServeMux, *httptest.Server)

TestServer returns a httptest.Server + servermux for handlers + client which proxies to the server

Types

type DBConfig added in v0.4.0

type DBConfig struct {
	// contains filtered or unexported fields
}

DBConfig is a struct that holds the configuration for the database

type Option added in v0.4.0

type Option func(*DBConfig)

Option is a functional option for configuring the DBConfig

func WithExpiryMinutes added in v0.4.0

func WithExpiryMinutes(expiry int) Option

WithExpiryMinutes sets the expiration of the container, defaults to 10 minutes

func WithImage added in v0.4.0

func WithImage(image string) Option

WithImage sets the image used for docker tests

func WithMaxConn added in v0.4.0

func WithMaxConn(maxConn int) Option

WithMaxConn sets the max connections to the db container, defaults to 100

type RewriteTransport

type RewriteTransport struct {
	Transport http.RoundTripper
}

RewriteTransport rewrites https requests to http to avoid TLS tomfoolery

func (*RewriteTransport) RoundTrip

func (t *RewriteTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip rewrites the request scheme to http and calls through to RoundTripper

type TestFixture

type TestFixture struct {
	Pool *dockertest.Pool

	URI     string
	Dialect string
	// contains filtered or unexported fields
}

TestFixture is a struct that holds the pool, resource and URI for the database

func GetPostgresDockerTest

func GetPostgresDockerTest(image string, expiry time.Duration, maxConn int) (*TestFixture, error)

func GetTestURI

func GetTestURI(opts ...Option) *TestFixture

GetTestURI returns the dialect, connection string and if used a testcontainer for database connectivity in tests

Jump to

Keyboard shortcuts

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