mock

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package mock provides configurable test doubles for all platform interfaces. Each mock struct uses function pointers for customizable behavior and tracks all method calls for assertion in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockCall

type MockCall struct {
	Method string
	Args   []any
}

MockCall records a single method invocation for assertion purposes.

type MockCapabilityMapper

type MockCapabilityMapper struct {
	CanMapFn              func(capabilityType string) bool
	MapFn                 func(decl platform.CapabilityDeclaration, pctx *platform.PlatformContext) ([]platform.ResourcePlan, error)
	ValidateConstraintsFn func(decl platform.CapabilityDeclaration, constraints []platform.Constraint) []platform.ConstraintViolation

	Calls []MockCall
	// contains filtered or unexported fields
}

MockCapabilityMapper implements platform.CapabilityMapper with configurable function pointers.

func NewMockCapabilityMapper

func NewMockCapabilityMapper() *MockCapabilityMapper

NewMockCapabilityMapper returns a MockCapabilityMapper with sensible defaults.

func (*MockCapabilityMapper) CanMap

func (m *MockCapabilityMapper) CanMap(capabilityType string) bool

func (*MockCapabilityMapper) GetCalls

func (m *MockCapabilityMapper) GetCalls() []MockCall

GetCalls returns a copy of the recorded calls.

func (*MockCapabilityMapper) Map

func (*MockCapabilityMapper) ValidateConstraints

type MockCredentialBroker

type MockCredentialBroker struct {
	IssueCredentialFn   func(ctx context.Context, pctx *platform.PlatformContext, request platform.CredentialRequest) (*platform.CredentialRef, error)
	RevokeCredentialFn  func(ctx context.Context, ref *platform.CredentialRef) error
	ResolveCredentialFn func(ctx context.Context, ref *platform.CredentialRef) (string, error)
	RotateCredentialFn  func(ctx context.Context, ref *platform.CredentialRef) (*platform.CredentialRef, error)
	ListCredentialsFn   func(ctx context.Context, pctx *platform.PlatformContext) ([]*platform.CredentialRef, error)

	Calls []MockCall
	// contains filtered or unexported fields
}

MockCredentialBroker implements platform.CredentialBroker with configurable function pointers.

func NewMockCredentialBroker

func NewMockCredentialBroker() *MockCredentialBroker

NewMockCredentialBroker returns a MockCredentialBroker with sensible defaults.

func (*MockCredentialBroker) GetCalls

func (m *MockCredentialBroker) GetCalls() []MockCall

GetCalls returns a copy of the recorded calls.

func (*MockCredentialBroker) IssueCredential

func (*MockCredentialBroker) ListCredentials

func (*MockCredentialBroker) ResolveCredential

func (m *MockCredentialBroker) ResolveCredential(ctx context.Context, ref *platform.CredentialRef) (string, error)

func (*MockCredentialBroker) RevokeCredential

func (m *MockCredentialBroker) RevokeCredential(ctx context.Context, ref *platform.CredentialRef) error

func (*MockCredentialBroker) RotateCredential

type MockLockHandle

type MockLockHandle struct {
	UnlockFn  func(ctx context.Context) error
	RefreshFn func(ctx context.Context, ttl time.Duration) error
	// contains filtered or unexported fields
}

MockLockHandle implements platform.LockHandle for use with MockStateStore.

func (*MockLockHandle) Refresh

func (h *MockLockHandle) Refresh(ctx context.Context, ttl time.Duration) error

func (*MockLockHandle) Unlock

func (h *MockLockHandle) Unlock(ctx context.Context) error

type MockProvider

type MockProvider struct {
	NameFn             func() string
	VersionFn          func() string
	InitializeFn       func(ctx context.Context, config map[string]any) error
	CapabilitiesFn     func() []platform.CapabilityType
	MapCapabilityFn    func(ctx context.Context, decl platform.CapabilityDeclaration, pctx *platform.PlatformContext) ([]platform.ResourcePlan, error)
	ResourceDriverFn   func(resourceType string) (platform.ResourceDriver, error)
	CredentialBrokerFn func() platform.CredentialBroker
	StateStoreFn       func() platform.StateStore
	HealthyFn          func(ctx context.Context) error
	CloseFn            func() error

	Calls []MockCall
	// contains filtered or unexported fields
}

MockProvider implements platform.Provider with configurable function pointers.

func NewMockProvider

func NewMockProvider() *MockProvider

NewMockProvider returns a MockProvider with sensible defaults.

func (*MockProvider) Capabilities

func (m *MockProvider) Capabilities() []platform.CapabilityType

func (*MockProvider) Close

func (m *MockProvider) Close() error

func (*MockProvider) CredentialBroker

func (m *MockProvider) CredentialBroker() platform.CredentialBroker

func (*MockProvider) GetCalls

func (m *MockProvider) GetCalls() []MockCall

GetCalls returns a copy of the recorded calls.

func (*MockProvider) Healthy

func (m *MockProvider) Healthy(ctx context.Context) error

func (*MockProvider) Initialize

func (m *MockProvider) Initialize(ctx context.Context, config map[string]any) error

func (*MockProvider) MapCapability

func (*MockProvider) Name

func (m *MockProvider) Name() string

func (*MockProvider) ResourceDriver

func (m *MockProvider) ResourceDriver(resourceType string) (platform.ResourceDriver, error)

func (*MockProvider) StateStore

func (m *MockProvider) StateStore() platform.StateStore

func (*MockProvider) Version

func (m *MockProvider) Version() string

type MockResourceDriver

type MockResourceDriver struct {
	CreateFn      func(ctx context.Context, name string, properties map[string]any) (*platform.ResourceOutput, error)
	ReadFn        func(ctx context.Context, name string) (*platform.ResourceOutput, error)
	UpdateFn      func(ctx context.Context, name string, current, desired map[string]any) (*platform.ResourceOutput, error)
	DeleteFn      func(ctx context.Context, name string) error
	HealthCheckFn func(ctx context.Context, name string) (*platform.HealthStatus, error)
	ScaleFn       func(ctx context.Context, name string, scaleParams map[string]any) (*platform.ResourceOutput, error)
	DiffFn        func(ctx context.Context, name string, desired map[string]any) ([]platform.DiffEntry, error)

	Calls []MockCall
	// contains filtered or unexported fields
}

MockResourceDriver implements platform.ResourceDriver with configurable function pointers.

func NewMockResourceDriver

func NewMockResourceDriver(resourceType string) *MockResourceDriver

NewMockResourceDriver returns a MockResourceDriver for the given resource type.

func (*MockResourceDriver) Create

func (m *MockResourceDriver) Create(ctx context.Context, name string, properties map[string]any) (*platform.ResourceOutput, error)

func (*MockResourceDriver) Delete

func (m *MockResourceDriver) Delete(ctx context.Context, name string) error

func (*MockResourceDriver) Diff

func (m *MockResourceDriver) Diff(ctx context.Context, name string, desired map[string]any) ([]platform.DiffEntry, error)

func (*MockResourceDriver) GetCalls

func (m *MockResourceDriver) GetCalls() []MockCall

GetCalls returns a copy of the recorded calls.

func (*MockResourceDriver) HealthCheck

func (m *MockResourceDriver) HealthCheck(ctx context.Context, name string) (*platform.HealthStatus, error)

func (*MockResourceDriver) Read

func (*MockResourceDriver) ResourceType

func (m *MockResourceDriver) ResourceType() string

func (*MockResourceDriver) Scale

func (m *MockResourceDriver) Scale(ctx context.Context, name string, scaleParams map[string]any) (*platform.ResourceOutput, error)

func (*MockResourceDriver) Update

func (m *MockResourceDriver) Update(ctx context.Context, name string, current, desired map[string]any) (*platform.ResourceOutput, error)

type MockStateStore

type MockStateStore struct {
	SaveResourceFn   func(ctx context.Context, contextPath string, output *platform.ResourceOutput) error
	GetResourceFn    func(ctx context.Context, contextPath, resourceName string) (*platform.ResourceOutput, error)
	ListResourcesFn  func(ctx context.Context, contextPath string) ([]*platform.ResourceOutput, error)
	DeleteResourceFn func(ctx context.Context, contextPath, resourceName string) error
	SavePlanFn       func(ctx context.Context, plan *platform.Plan) error
	GetPlanFn        func(ctx context.Context, planID string) (*platform.Plan, error)
	ListPlansFn      func(ctx context.Context, contextPath string, limit int) ([]*platform.Plan, error)
	LockFn           func(ctx context.Context, contextPath string, ttl time.Duration) (platform.LockHandle, error)
	DependenciesFn   func(ctx context.Context, contextPath, resourceName string) ([]platform.DependencyRef, error)
	AddDependencyFn  func(ctx context.Context, dep platform.DependencyRef) error

	Calls []MockCall
	// contains filtered or unexported fields
}

MockStateStore implements platform.StateStore with configurable function pointers and in-memory storage that works out of the box.

func NewMockStateStore

func NewMockStateStore() *MockStateStore

NewMockStateStore returns a MockStateStore with initialized in-memory maps.

func (*MockStateStore) AddDependency

func (m *MockStateStore) AddDependency(ctx context.Context, dep platform.DependencyRef) error

func (*MockStateStore) DeleteResource

func (m *MockStateStore) DeleteResource(ctx context.Context, contextPath, resourceName string) error

func (*MockStateStore) Dependencies

func (m *MockStateStore) Dependencies(ctx context.Context, contextPath, resourceName string) ([]platform.DependencyRef, error)

func (*MockStateStore) GetCalls

func (m *MockStateStore) GetCalls() []MockCall

GetCalls returns a copy of the recorded calls.

func (*MockStateStore) GetPlan

func (m *MockStateStore) GetPlan(ctx context.Context, planID string) (*platform.Plan, error)

func (*MockStateStore) GetResource

func (m *MockStateStore) GetResource(ctx context.Context, contextPath, resourceName string) (*platform.ResourceOutput, error)

func (*MockStateStore) ListPlans

func (m *MockStateStore) ListPlans(ctx context.Context, contextPath string, limit int) ([]*platform.Plan, error)

func (*MockStateStore) ListResources

func (m *MockStateStore) ListResources(ctx context.Context, contextPath string) ([]*platform.ResourceOutput, error)

func (*MockStateStore) Lock

func (m *MockStateStore) Lock(ctx context.Context, contextPath string, ttl time.Duration) (platform.LockHandle, error)

func (*MockStateStore) SavePlan

func (m *MockStateStore) SavePlan(ctx context.Context, plan *platform.Plan) error

func (*MockStateStore) SaveResource

func (m *MockStateStore) SaveResource(ctx context.Context, contextPath string, output *platform.ResourceOutput) error

Jump to

Keyboard shortcuts

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