testutil

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package testutil provides mock implementations for use in tests across the aura-client module. Nothing in this package should be imported by production code — it exists solely to share test helpers between internal packages without putting mock types inside the packages they mock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockHTTPCall

type MockHTTPCall struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    string
}

MockHTTPCall records the details of a single call to MockHTTPService.

type MockHTTPService

type MockHTTPService struct {
	// Default response returned when no method-specific response is set.
	Response *httpclient.HTTPResponse
	Error    error

	// Method-specific responses (take precedence over Response/Error).
	GetResponse    *httpclient.HTTPResponse
	GetError       error
	PostResponse   *httpclient.HTTPResponse
	PostError      error
	PutResponse    *httpclient.HTTPResponse
	PutError       error
	PatchResponse  *httpclient.HTTPResponse
	PatchError     error
	DeleteResponse *httpclient.HTTPResponse
	DeleteError    error

	// Call recording for assertions.
	LastMethod  string
	LastURL     string
	LastHeaders map[string]string
	LastBody    string
	CallCount   int
	CallHistory []MockHTTPCall
}

MockHTTPService is a test double for httpclient.HTTPService. It records every call made to it and can be pre-loaded with per-method responses so tests can exercise specific code paths without a network.

func NewMockHTTPService

func NewMockHTTPService() *MockHTTPService

NewMockHTTPService returns an empty MockHTTPService ready for use.

func (*MockHTTPService) Delete

func (m *MockHTTPService) Delete(_ context.Context, url string, headers map[string]string) (*httpclient.HTTPResponse, error)

Delete implements httpclient.HTTPService.

func (*MockHTTPService) Get

Get implements httpclient.HTTPService.

func (*MockHTTPService) Patch

func (m *MockHTTPService) Patch(_ context.Context, url string, headers map[string]string, body string) (*httpclient.HTTPResponse, error)

Patch implements httpclient.HTTPService.

func (*MockHTTPService) Post

func (m *MockHTTPService) Post(_ context.Context, url string, headers map[string]string, body string) (*httpclient.HTTPResponse, error)

Post implements httpclient.HTTPService.

func (*MockHTTPService) Put

func (m *MockHTTPService) Put(_ context.Context, url string, headers map[string]string, body string) (*httpclient.HTTPResponse, error)

Put implements httpclient.HTTPService.

func (*MockHTTPService) Reset

func (m *MockHTTPService) Reset()

Reset clears all recorded calls and configured responses.

func (*MockHTTPService) WithError

func (m *MockHTTPService) WithError(err error) *MockHTTPService

WithError configures a default error for all HTTP methods.

func (*MockHTTPService) WithGetResponse

func (m *MockHTTPService) WithGetResponse(statusCode int, body string) *MockHTTPService

WithGetResponse configures a response returned only for GET requests.

func (*MockHTTPService) WithPostResponse

func (m *MockHTTPService) WithPostResponse(statusCode int, body string) *MockHTTPService

WithPostResponse configures a response returned only for POST requests.

func (*MockHTTPService) WithResponse

func (m *MockHTTPService) WithResponse(statusCode int, body string) *MockHTTPService

WithResponse configures a default response for all HTTP methods.

Jump to

Keyboard shortcuts

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