testutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package testutil provides shared test helpers for canvas-cli.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockCanvas

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

MockCanvas is a test HTTP server that simulates Canvas API endpoints.

func NewMockCanvas

func NewMockCanvas() *MockCanvas

NewMockCanvas creates and starts a new mock Canvas HTTP server.

func (*MockCanvas) Close

func (m *MockCanvas) Close()

Close shuts down the underlying httptest.Server.

func (*MockCanvas) LastRequest

func (m *MockCanvas) LastRequest() *RecordedRequest

LastRequest returns the most recent RecordedRequest, or nil if

func (*MockCanvas) On

func (m *MockCanvas) On(method, path string, statusCode int, body any)

On registers a handler for the given HTTP method and path.

func (*MockCanvas) OnUploadInit

func (m *MockCanvas) OnUploadInit(method, path, uploadPath string, params map[string]string)

OnUploadInit registers a route that returns a 200 with upload_url and

func (*MockCanvas) OnUploadRedirect

func (m *MockCanvas) OnUploadRedirect(method, path, redirectPath string)

OnUploadRedirect registers a route that responds with HTTP 302 and a

func (*MockCanvas) RequestCount

func (m *MockCanvas) RequestCount() int

RequestCount returns the number of requests received by the mock server.

func (*MockCanvas) RequestLog

func (m *MockCanvas) RequestLog() []RecordedRequest

RequestLog returns a copy of all recorded requests.

func (*MockCanvas) Reset

func (m *MockCanvas) Reset()

Reset clears the request log and resets pagination state.

func (*MockCanvas) SetPagination

func (m *MockCanvas) SetPagination(path string, pages [][]map[string]any)

SetPagination configures paginated responses for the given path.

func (*MockCanvas) SetRateLimitHeaders

func (m *MockCanvas) SetRateLimitHeaders(cost, remaining float64)

SetRateLimitHeaders configures the mock to include rate limit

func (*MockCanvas) SetRetryAfter

func (m *MockCanvas) SetRetryAfter(seconds int)

SetRetryAfter configures the mock to return HTTP 429 with a

func (*MockCanvas) URL

func (m *MockCanvas) URL() string

URL returns the base URL of the mock server.

type RecordedRequest

type RecordedRequest struct {
	Method  string
	Path    string
	Query   url.Values
	Headers http.Header
	Body    string
}

RecordedRequest captures the details of a single HTTP request

Jump to

Keyboard shortcuts

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