testutils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const TestServerVersion = "test"

Variables

View Source
var CancelledContextMatcher = mock.MatchedBy(func(ctx context.Context) bool {
	if ctx == nil {
		return false
	}

	select {
	case <-ctx.Done():
		return ctx.Err() == context.Canceled
	default:
		return false
	}
})
View Source
var (
	ErrSessionNotFound = errors.New("session not found")
)

Functions

func AllServerToolNames

func AllServerToolNames() []string

func AssertHandlerError

func AssertHandlerError(t *testing.T, err error, mcpResult *mcp.CallToolResult, output interface{}, wantErrContains string)

AssertHandlerError is a helper to assert that a tool handler returned an expected error

func AssertMcpCallError

func AssertMcpCallError(t *testing.T, result *mcp.CallToolResult, wantErrContains string)

AssertMcpCallError is a helper to assert that an MCP call returned an expected error

func AssertMcpCallSuccess

func AssertMcpCallSuccess(t *testing.T, err error, result *mcp.CallToolResult)

AssertMcpCallSuccess is a helper to assert that an MCP call succeeded

func AssertStructuredHandlerSuccess

func AssertStructuredHandlerSuccess(t *testing.T, err error, mcpResult *mcp.CallToolResult, output interface{})

AssertStructuredHandlerSuccess is a helper to assert that a tool handler that returns structured output succeeded

func AssertUnstructuredHandlerSuccess

func AssertUnstructuredHandlerSuccess(t *testing.T, err error, mcpResult *mcp.CallToolResult, output interface{})

AssertUnstructuredHandlerSuccess is a helper to assert that a tool handler that returns unstructured output succeeded

func AssertUnstructuredOutputMatches

func AssertUnstructuredOutputMatches(t *testing.T, mcpResult *mcp.CallToolResult, expectedOutput any)

func ExecuteCliLogoutCommand

func ExecuteCliLogoutCommand(t *testing.T, ctx context.Context, tokenStoreFactory tokenstore.TokenStoreFactory, args ...string) (err error)

func ExecuteCliRootCommand

func ExecuteCliRootCommand(t *testing.T, ctx context.Context, args ...string) (err error)

func ExecuteCliRunCommand

func ExecuteCliRunCommand(t *testing.T, ctx context.Context, tokenStoreFactory tokenstore.TokenStoreFactory, clientFactory sdk.ClientFactory, legacyClientFactory legacy.ClientFactory, authClientFactory client.AuthClientFactory, transport mcp.Transport, args ...string) (err error)

func ExecuteCliSessionCommand

func ExecuteCliSessionCommand(t *testing.T, ctx context.Context, tokenStoreFactory tokenstore.TokenStoreFactory, args ...string) (err error)

func MockContextInitializer

func MockContextInitializer() func(ctx context.Context) (context.Context, error)

Just returns the context as-is, without modification or error

func MockContextInitializerWithError

func MockContextInitializerWithError(err error) func(ctx context.Context) (context.Context, error)

Returns a context initializer that always returns the specified error

func MockLegacySdkPaginationIterator

func MockLegacySdkPaginationIterator(pages []LegacySdkMockPage) management.EntityArrayPagedIterator

func MockPaginationIterator

func MockPaginationIterator[T pingone.MappedNullable](pages []MockPage[T]) pingone.PagedIterator[T]

func Pointer

func Pointer[T any](v T) *T

func ReadOnlyToolNames

func ReadOnlyToolNames() []string

func WriteToolNames

func WriteToolNames() []string

Types

type APIErrorTestCase

type APIErrorTestCase struct {
	Name            string
	StatusCode      int
	ApiError        error
	WantErrContains string
}

APIErrorTestCase represents a test case for API error scenarios

func CommonAPIErrorTestCases

func CommonAPIErrorTestCases() []APIErrorTestCase

type InMemoryTokenStore

type InMemoryTokenStore struct {

	// Errors to simulate failures for testing
	PutSessionError    error
	GetSessionError    error
	HasSessionError    error
	DeleteSessionError error
	// contains filtered or unexported fields
}

func NewInMemoryTokenStore

func NewInMemoryTokenStore() *InMemoryTokenStore

func NewInMemoryTokenStoreWithDefaultSession

func NewInMemoryTokenStoreWithDefaultSession() *InMemoryTokenStore

func (*InMemoryTokenStore) DeleteSession

func (s *InMemoryTokenStore) DeleteSession() error

func (*InMemoryTokenStore) GetSession

func (s *InMemoryTokenStore) GetSession() (*auth.AuthSession, error)

func (*InMemoryTokenStore) HasSession

func (s *InMemoryTokenStore) HasSession() (bool, error)

func (*InMemoryTokenStore) PutSession

func (s *InMemoryTokenStore) PutSession(session auth.AuthSession) error

type LegacySdkMockPage

type LegacySdkMockPage struct {
	EntityArray  *management.EntityArray
	HTTPResponse *http.Response
	Error        error
}

type MockAuthClient

type MockAuthClient struct {
	mock.Mock
}

func NewMockAuthClient

func NewMockAuthClient(tokenSource oauth2.TokenSource) *MockAuthClient

func (*MockAuthClient) BrowserLoginAvailable

func (m *MockAuthClient) BrowserLoginAvailable(grantType auth.GrantType) bool

func (*MockAuthClient) TokenSource

func (m *MockAuthClient) TokenSource(ctx context.Context, grantType auth.GrantType) (oauth2.TokenSource, error)

type MockAuthClientFactory

type MockAuthClientFactory struct {
	mock.Mock
}

func NewEmptyMockAuthClientFactory

func NewEmptyMockAuthClientFactory() *MockAuthClientFactory

func NewMockAuthClientFactory

func NewMockAuthClientFactory(tokenSource oauth2.TokenSource) *MockAuthClientFactory

func (*MockAuthClientFactory) NewAuthClient

func (f *MockAuthClientFactory) NewAuthClient() (client.AuthClient, error)

type MockPage

type MockPage[T any] struct {
	Data         *T
	HTTPResponse *http.Response
	Error        error
}

type MockTokenStoreFactory

type MockTokenStoreFactory struct {
	mock.Mock
}

MockTokenStoreFactory is a mock implementation of tokenstore.TokenStoreFactory using testify mock

func NewMockTokenStoreFactory

func NewMockTokenStoreFactory() *MockTokenStoreFactory

func NewMockTokenStoreFactoryWithError

func NewMockTokenStoreFactoryWithError(err error) *MockTokenStoreFactory

NewMockTokenStoreFactoryWithError creates a MockTokenStoreFactory that returns an error for any StoreType

func NewMockTokenStoreFactoryWithStore

func NewMockTokenStoreFactoryWithStore(store tokenstore.TokenStore) *MockTokenStoreFactory

NewMockTokenStoreFactoryWithStore creates a MockTokenStoreFactory that returns the given store for any StoreType

func (*MockTokenStoreFactory) NewTokenStore

func (m *MockTokenStoreFactory) NewTokenStore(storeType tokenstore.StoreType) (tokenstore.TokenStore, error)

type StaticTokenSource

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

func NewDefaultStaticTokenSource

func NewDefaultStaticTokenSource() *StaticTokenSource

func NewStaticTokenSource

func NewStaticTokenSource(token *oauth2.Token) *StaticTokenSource

func (*StaticTokenSource) Token

func (s *StaticTokenSource) Token() (*oauth2.Token, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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