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 ¶
- func AssertEqual(t *testing.T, got, want interface{})
- func AssertError(t *testing.T, err error)
- func AssertFalse(t *testing.T, condition bool, message string)
- func AssertNil(t *testing.T, v interface{})
- func AssertNoError(t *testing.T, err error)
- func AssertNotEqual(t *testing.T, got, want interface{})
- func AssertNotNil(t *testing.T, v interface{})
- func AssertStringContains(t *testing.T, s, substr string)
- func AssertTimeEqual(t *testing.T, got, want time.Time, tolerance time.Duration)
- func AssertTrue(t *testing.T, condition bool, message string)
- func BoolPtr(v bool) *bool
- func GeneratePKCEPair() (challenge, verifier string)
- func GenerateRandomString(length int) string
- func GenerateTestAuthorizationCode() *storage.AuthorizationCode
- func GenerateTestAuthorizationState() *storage.AuthorizationState
- func GenerateTestClient() *storage.Client
- func GenerateTestToken() *oauth2.Token
- func GenerateTestTokenWithExpiry(expiry time.Time) *oauth2.Token
- func GenerateTestUserInfo() *providers.UserInfo
- func IntPtr(v int) *int
- func NewMockHTTPSServer(handler http.HandlerFunc) *httptest.Server
- func NewMockHTTPServer(handler http.HandlerFunc) *httptest.Server
- func StringPtr(v string) *string
- type HTTPRequest
- type MockTime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqual ¶
AssertEqual fails the test if got != want
func AssertError ¶
AssertError fails the test if err is nil
func AssertFalse ¶
AssertFalse fails the test if condition is true
func AssertNoError ¶
AssertNoError fails the test if err is not nil
func AssertNotEqual ¶
AssertNotEqual fails the test if got == want
func AssertNotNil ¶
AssertNotNil fails the test if v is nil
func AssertStringContains ¶
AssertStringContains fails the test if s does not contain substr
func AssertTimeEqual ¶
AssertTimeEqual asserts two times are equal within a tolerance
func AssertTrue ¶
AssertTrue fails the test if condition is false
func BoolPtr ¶ added in v0.2.51
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 ¶
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 ¶
GenerateTestClient creates a test OAuth client
func GenerateTestToken ¶
GenerateTestToken creates a test OAuth2 token
func GenerateTestTokenWithExpiry ¶
GenerateTestTokenWithExpiry creates a test OAuth2 token with specific expiry
func GenerateTestUserInfo ¶
GenerateTestUserInfo creates test user information
func IntPtr ¶ added in v0.2.51
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
Types ¶
type HTTPRequest ¶
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 ¶
func (r *HTTPRequest) Do(handler http.Handler) *httptest.ResponseRecorder
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 ¶
NewMockTime creates a new mock time provider