testutils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(t *testing.T) context.Context

func ContextWithVerboseLogger

func ContextWithVerboseLogger(t *testing.T) context.Context

Types

type ErrorTransport

type ErrorTransport struct{}

ErrorTransport is custom transport that always produces a simulated network error.

func (*ErrorTransport) RoundTrip

func (t *ErrorTransport) RoundTrip(_ *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface and returns a simulated network error.

type Response added in v0.2.0

type Response struct {
	ResponseCode int
	ResponseBody string
}

type ResponseDef added in v0.2.0

type ResponseDef struct {
	GET             func(*testing.T, *http.Request) Response
	PUT             func(*testing.T, *http.Request) Response
	POST            func(*testing.T, *http.Request) Response
	DELETE          func(*testing.T, *http.Request) Response
	ValidateRequest func(*testing.T, *http.Request)
}

func (ResponseDef) Delete added in v0.2.0

func (r ResponseDef) Delete(t *testing.T, req *http.Request) Response

func (ResponseDef) Get added in v0.2.0

func (r ResponseDef) Get(t *testing.T, req *http.Request) Response

func (ResponseDef) Post added in v0.2.0

func (r ResponseDef) Post(t *testing.T, req *http.Request) Response

func (ResponseDef) Put added in v0.2.0

func (r ResponseDef) Put(t *testing.T, req *http.Request) Response

func (ResponseDef) Validate added in v0.2.0

func (r ResponseDef) Validate(t *testing.T, req *http.Request)

type TestServer

type TestServer struct {
	*httptest.Server // Embedded httptest.Server for underlying server functionality.
	// contains filtered or unexported fields
}

TestServer is a wrapper around httptest.Server that provides utility methods for testing.

func NewHTTPTestServer

func NewHTTPTestServer(t *testing.T, responses []ResponseDef) *TestServer

NewHTTPTestServer creates a new HTTP test server with the specified responses for each HTTP method.

func (TestServer) Calls added in v0.2.0

func (t TestServer) Calls() int

Calls returns the number of calls invoked on the test server

func (TestServer) Client

func (t TestServer) Client() *http.Client

Client returns an HTTP client associated with the test server.

func (TestServer) FaultyClient

func (t TestServer) FaultyClient() *http.Client

FaultyClient returns an HTTP client associated with the test server that always produces a network error.

func (TestServer) URL

func (t TestServer) URL() *url.URL

URL returns the URL of the test server.

Jump to

Keyboard shortcuts

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