testutil

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides testing utilities for the Spooled SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockResponse

type MockResponse struct {
	StatusCode int
	Body       any
	Headers    map[string]string
}

MockResponse represents a mock HTTP response.

type MockServer

type MockServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

MockServer is a test HTTP server for mocking API responses.

func NewMockServer

func NewMockServer(t *testing.T) *MockServer

NewMockServer creates a new mock server.

func (*MockServer) AssertLastRequestHeader

func (ms *MockServer) AssertLastRequestHeader(t *testing.T, key, expected string)

AssertLastRequestHeader asserts a header of the last request.

func (*MockServer) AssertLastRequestMethod

func (ms *MockServer) AssertLastRequestMethod(t *testing.T, expected string)

AssertLastRequestMethod asserts the method of the last request.

func (*MockServer) AssertLastRequestPath

func (ms *MockServer) AssertLastRequestPath(t *testing.T, expected string)

AssertLastRequestPath asserts the path of the last request.

func (*MockServer) AssertRequestCount

func (ms *MockServer) AssertRequestCount(t *testing.T, expected int)

AssertRequestCount asserts that a specific number of requests were made.

func (*MockServer) ClearRequests

func (ms *MockServer) ClearRequests()

ClearRequests clears all recorded requests.

func (*MockServer) GetRequests

func (ms *MockServer) GetRequests() []RecordedRequest

GetRequests returns all recorded requests.

func (*MockServer) Handle

func (ms *MockServer) Handle(method, path string, handler http.HandlerFunc)

Handle registers a handler for a specific method and path.

func (*MockServer) HandleError

func (ms *MockServer) HandleError(method, path string, statusCode int, code, message string)

HandleError registers a handler that returns an error response.

func (*MockServer) HandleJSON

func (ms *MockServer) HandleJSON(method, path string, statusCode int, response any)

HandleJSON registers a handler that returns a JSON response.

func (*MockServer) LastRequest

func (ms *MockServer) LastRequest() *RecordedRequest

LastRequest returns the last recorded request.

func (*MockServer) ParseLastRequestBody

func (ms *MockServer) ParseLastRequestBody(t *testing.T, v any)

ParseLastRequestBody parses the body of the last request as JSON.

type RecordedRequest

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

RecordedRequest represents a recorded HTTP request.

Jump to

Keyboard shortcuts

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