testutil

package
v0.2.75 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package testutil provides testing utilities, mock implementations, and test fixtures for the mcp-oauth library. It includes helpers for creating test data, assertions, and mock time providers for deterministic testing.

Package testutil provides testing utilities and helpers for the mcp-oauth library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t *testing.T, got, want interface{})

AssertEqual fails the test if got != want

func AssertError

func AssertError(t *testing.T, err error)

AssertError fails the test if err is nil

func AssertFalse

func AssertFalse(t *testing.T, condition bool, message string)

AssertFalse fails the test if condition is true

func AssertNil

func AssertNil(t *testing.T, v interface{})

AssertNil fails the test if v is not nil

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError fails the test if err is not nil

func AssertNotEqual

func AssertNotEqual(t *testing.T, got, want interface{})

AssertNotEqual fails the test if got == want

func AssertNotNil

func AssertNotNil(t *testing.T, v interface{})

AssertNotNil fails the test if v is nil

func AssertStringContains

func AssertStringContains(t *testing.T, s, substr string)

AssertStringContains fails the test if s does not contain substr

func AssertTimeEqual

func AssertTimeEqual(t *testing.T, got, want time.Time, tolerance time.Duration)

AssertTimeEqual asserts two times are equal within a tolerance

func AssertTrue

func AssertTrue(t *testing.T, condition bool, message string)

AssertTrue fails the test if condition is false

func BoolPtr added in v0.2.51

func BoolPtr(v bool) *bool

BoolPtr returns a pointer to the given bool value. This is useful in tests for creating pointer values inline.

func GeneratePKCEPair added in v0.1.16

func GeneratePKCEPair() (challenge, verifier string)

GeneratePKCEPair generates a valid PKCE challenge and verifier pair for testing. Returns (challenge, verifier) where challenge is the S256 hash of the verifier. This is a convenience helper to reduce code duplication in PKCE tests.

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString generates a random base64-encoded string

func GenerateTestAuthorizationCode

func GenerateTestAuthorizationCode() *storage.AuthorizationCode

GenerateTestAuthorizationCode creates a test authorization code

func GenerateTestAuthorizationState

func GenerateTestAuthorizationState() *storage.AuthorizationState

GenerateTestAuthorizationState creates a test authorization state

func GenerateTestClient

func GenerateTestClient() *storage.Client

GenerateTestClient creates a test OAuth client

func GenerateTestToken

func GenerateTestToken() *oauth2.Token

GenerateTestToken creates a test OAuth2 token

func GenerateTestTokenWithExpiry

func GenerateTestTokenWithExpiry(expiry time.Time) *oauth2.Token

GenerateTestTokenWithExpiry creates a test OAuth2 token with specific expiry

func GenerateTestUserInfo

func GenerateTestUserInfo() *providers.UserInfo

GenerateTestUserInfo creates test user information

func IntPtr added in v0.2.51

func IntPtr(v int) *int

IntPtr returns a pointer to the given int value. This is useful in tests for creating pointer values inline.

func NewMockHTTPSServer

func NewMockHTTPSServer(handler http.HandlerFunc) *httptest.Server

NewMockHTTPSServer creates a test HTTPS server with the given handler

func NewMockHTTPServer

func NewMockHTTPServer(handler http.HandlerFunc) *httptest.Server

NewMockHTTPServer creates a test HTTP server with the given handler

func StringPtr added in v0.2.51

func StringPtr(v string) *string

StringPtr returns a pointer to the given string value. This is useful in tests for creating pointer values inline.

Types

type HTTPRequest

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

HTTPRequest is a helper for making test HTTP requests

func NewHTTPRequest

func NewHTTPRequest(method, url string) *HTTPRequest

NewHTTPRequest creates a new HTTP request helper

func (*HTTPRequest) Do

Do executes the HTTP request

func (*HTTPRequest) WithBody

func (r *HTTPRequest) WithBody(body string) *HTTPRequest

WithBody sets the request body

func (*HTTPRequest) WithHeader

func (r *HTTPRequest) WithHeader(key, value string) *HTTPRequest

WithHeader adds a header to the request

type MockTime

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

MockTime provides a controllable time source for deterministic testing

func NewMockTime

func NewMockTime(t time.Time) *MockTime

NewMockTime creates a new mock time provider

func (*MockTime) Advance

func (m *MockTime) Advance(d time.Duration)

Advance moves the mock time forward by the given duration

func (*MockTime) Now

func (m *MockTime) Now() time.Time

Now returns the current mock time

func (*MockTime) Set

func (m *MockTime) Set(t time.Time)

Set sets the mock time to a specific value

Jump to

Keyboard shortcuts

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