testutils

package
v0.0.0-...-7c6f6d5 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 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

type Response struct {
	ResponseCode int
	ResponseBody string
}

type ResponseDef

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

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

func (ResponseDef) Get

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

func (ResponseDef) Post

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

func (ResponseDef) Put

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

func (ResponseDef) Validate

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

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