testutils

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockHTTPClient

type MockHTTPClient struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

MockHTTPClient provides a way to mock HTTP responses for testing

func SetupMockHTTPClient

func SetupMockHTTPClient(t testing.TB) *MockHTTPClient

SetupMockHTTPClient creates a new mock HTTP client for testing

func (*MockHTTPClient) AssertNumberOfRequests

func (m *MockHTTPClient) AssertNumberOfRequests(t testing.TB, expected int)

AssertNumberOfRequests asserts the total number of requests made

func (*MockHTTPClient) AssertRequestMade

func (m *MockHTTPClient) AssertRequestMade(t testing.TB, urlPattern string)

AssertRequestMade asserts that a request was made to the given URL

func (*MockHTTPClient) GetRequests

func (m *MockHTTPClient) GetRequests() []RecordedRequest

GetRequests returns all recorded requests

func (*MockHTTPClient) GetRequestsTo

func (m *MockHTTPClient) GetRequestsTo(urlPattern string) []RecordedRequest

GetRequestsTo returns all recorded requests to a specific URL pattern

func (*MockHTTPClient) SetResponse

func (m *MockHTTPClient) SetResponse(urlPattern string, response MockResponse)

SetResponse configures a mock response for a specific URL pattern

func (*MockHTTPClient) SetResponseForRequest

func (m *MockHTTPClient) SetResponseForRequest(method, urlPattern string, response MockResponse)

SetResponseForRequest configures a mock response for a specific method and URL

type MockResponse

type MockResponse struct {
	StatusCode int
	Body       interface{} // Will be JSON marshaled if not string/[]byte
	Headers    map[string]string
	Error      error
}

MockResponse defines a mocked HTTP response

type MockTransport

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

MockTransport implements http.RoundTripper for intercepting HTTP requests

func (*MockTransport) RoundTrip

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

RoundTrip implements the http.RoundTripper interface

type PostgreSQLContainer added in v1.1.0

type PostgreSQLContainer struct {
	URL string
	// contains filtered or unexported fields
}

func SetupPostgreSQLContainer added in v1.1.0

func SetupPostgreSQLContainer(t testing.TB) *PostgreSQLContainer

type RecordedRequest

type RecordedRequest struct {
	Method  string
	URL     string
	Headers http.Header
	Body    []byte
}

RecordedRequest stores information about requests made

Jump to

Keyboard shortcuts

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