apitest

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package apitest provides utilities for testing the Twitch API Client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockTwitchAPI

type MockTwitchAPI struct {
	BaseURL string
	// contains filtered or unexported fields
}

MockTwitchAPI represents a mock Twitch API server.

func NewMockAPI

func NewMockAPI(t TestingT, opts ...MockTwitchAPIOption) *MockTwitchAPI

NewMockAPI creates a mock Twitch API server for testing purposes.

func (*MockTwitchAPI) Certificate

func (m *MockTwitchAPI) Certificate() *x509.Certificate

Certificate returns the TLS certificate used by the mock server.

func (*MockTwitchAPI) Client

func (m *MockTwitchAPI) Client() *http.Client

Client returns a HTTP client to use with the mock server.

func (*MockTwitchAPI) NewBearerToken

func (m *MockTwitchAPI) NewBearerToken(clientID string) (token string, err error)

NewBearerToken simulates generating a new bearer token for the given client ID.

func (*MockTwitchAPI) RegisterApplication

func (m *MockTwitchAPI) RegisterApplication() (clientID, clientSecret string, err error)

RegisterApplication simulates registering a new Twitch application and returns a client ID and secret.

func (*MockTwitchAPI) ServeHTTP

func (m *MockTwitchAPI) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP implements the net/http.Handler interface for MockTwitchAPI.

type MockTwitchAPIEndpoint

type MockTwitchAPIEndpoint struct {
	TimesCalled int
	Successes   int
	Failures    int
	// contains filtered or unexported fields
}

MockTwitchAPIEndpoint represents available data for a mock Twitch API endpoint.

func SetMockResponse

func SetMockResponse[T any, V api.ResponseData[T]](m *MockTwitchAPI, method, path string, data *V, validators ...ValidatorFunc) *MockTwitchAPIEndpoint

SetMockResponse adds a mock response for the given path.

If a response has already been added for the given path and method, it will be overwritten.

func SetMockValidator

func SetMockValidator(m *MockTwitchAPI, method, path string, validators ...ValidatorFunc) *MockTwitchAPIEndpoint

SetMockValidator adds a mock validator for the given path.

Successful requests will return an empty response.

If a response has already been added for the given path and method, it will be overwritten.

type MockTwitchAPIOption

type MockTwitchAPIOption func(*MockTwitchAPI)

MockTwitchAPIOption represents an option for configuring the MockTwitchAPI.

func EnableHTTP2

func EnableHTTP2() MockTwitchAPIOption

EnableHTTP2 configures the mock server to support HTTP/2.

func WithTLS

func WithTLS() MockTwitchAPIOption

WithTLS configures the mock server to use HTTPS.

type TestingT

type TestingT interface {
	Cleanup(func())
}

TestingT is an interface for the testing.T type.

type ValidatorFunc

type ValidatorFunc func(req *http.Request) error

ValidatorFunc is a function type for validating incoming HTTP requests.

func BodyParamEquals

func BodyParamEquals(key, value string) ValidatorFunc

BodyParamEquals returns a ValidatorFunc that checks if a body parameter equals a specific value.

func QueryParamEquals

func QueryParamEquals(key, value string) ValidatorFunc

QueryParamEquals returns a ValidatorFunc that checks if a query parameter equals a specific value.

func RequireBodyParam

func RequireBodyParam(key string) ValidatorFunc

RequireBodyParam returns a ValidatorFunc that checks for the presence of a body parameter.

func RequireQueryParam

func RequireQueryParam(key string) ValidatorFunc

RequireQueryParam returns a ValidatorFunc that checks for the presence of a query parameter.

Jump to

Keyboard shortcuts

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