# features

import "github.com/matzefriedrich/parsley/pkg/features"

# Index

  • func RegisterLazy[T any](registry types.ServiceRegistry, activatorFunc func() T, _ types.LifetimeScope) error
  • func RegisterList[T any](registry types.ServiceRegistry) error
  • func RegisterNamed[T any](registry types.ServiceRegistry, services ...registration.NamedServiceRegistrationFunc) error
  • type ArgMatch
    • func Exact[T comparable](expected T) ArgMatch
    • func IsAny() ArgMatch
  • type Interceptor
  • type InterceptorBase
    • func NewInterceptorBase(name string, position int) InterceptorBase
    • func (i InterceptorBase) Name() string
    • func (i InterceptorBase) Position() int
  • type Lazy
  • type MethodCallContext
    • func NewMethodCallContext(methodName string, parameters map[string]interface{}) *MethodCallContext
  • type MethodInterceptor
  • type MockBase
    • func NewMockBase() MockBase
    • func (m *MockBase) AddFunction(name string, signature string)
    • func (m *MockBase) TraceMethodCall(name string, arguments ...any)
    • func (m *MockBase) Verify(name string, times TimesFunc, matches ...ArgMatch) bool
  • type MockFunction
    • func (m MockFunction) String() string
  • type ParameterInfo
    • func (p ParameterInfo) String() string
  • type ProxyBase
    • func NewProxyBase[T any](target T, interceptors []MethodInterceptor) ProxyBase
    • func (p *ProxyBase) InvokeEnterMethodInterceptors(callContext *MethodCallContext)
    • func (p *ProxyBase) InvokeExitMethodInterceptors(callContext *MethodCallContext)
    • func (p *ProxyBase) InvokeMethodErrorInterceptors(callContext *MethodCallContext, returnValues ...interface{})
  • type ReturnValueInfo
    • func (r ReturnValueInfo) String() string
  • type TimesFunc
    • func TimesAtLeastOnce() TimesFunc
    • func TimesExactly(n int) TimesFunc
    • func TimesNever() TimesFunc
    • func TimesOnce() TimesFunc

# func RegisterLazy

func RegisterLazy[T any](registry types.ServiceRegistry, activatorFunc func() T, _ types.LifetimeScope) error

RegisterLazy registers a lazily-activated service in the service registry using the provided activator function.

# func RegisterList

func RegisterList[T any](registry types.ServiceRegistry) error

RegisterList registers a function that resolves and returns a list of services of type T with the specified registry.

# func RegisterNamed

func RegisterNamed[T any](registry types.ServiceRegistry, services ...registration.NamedServiceRegistrationFunc) error

RegisterNamed registers named services with their respective activator functions and lifetime scopes. It supports dependency injection by associating names with service instances.

# type ArgMatch

ArgMatch is a function type used to match an argument against a certain condition during mock function verification.

type ArgMatch func(actual any) bool

# func Exact

func Exact[T comparable](expected T) ArgMatch

Exact returns an ArgMatch that checks if a given argument is exactly equal to the specified expected value.

# func IsAny

func IsAny() ArgMatch

IsAny always returns true, enabling it to match any given argument during mock function verification.

# type Interceptor

Interceptor is a base interface type for defining interceptors that can be used to monitor or alter the behavior of other components.

type Interceptor interface {
    Name() string
    Position() int
}

# type InterceptorBase

InterceptorBase serves as a foundational structure for defining interceptors, managing essential data like name and position.

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

# func NewInterceptorBase

func NewInterceptorBase(name string, position int) InterceptorBase

NewInterceptorBase creates a new instance of InterceptorBase with the specified name and position for managing interceptor metadata.

# func (InterceptorBase) Name

func (i InterceptorBase) Name() string

Name retrieves the name of the interceptor, which is useful for identification and debugging purposes.

# func (InterceptorBase) Position

func (i InterceptorBase) Position() int

Position returns the position of the interceptor, helping determine its order in processing flows within a system.

# type Lazy

Lazy represents a type whose value is initialized lazily upon first access, typically to improve performance or manage resources.

type Lazy[T any] interface {
    Value() T
}

# type MethodCallContext

MethodCallContext captures the context of a method call, including method name, parameters, and return values.

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

# func NewMethodCallContext

func NewMethodCallContext(methodName string, parameters map[string]interface{}) *MethodCallContext

NewMethodCallContext creates a new MethodCallContext instance with the provided method name and parameters.

# type MethodInterceptor

MethodInterceptor provides hooks to intercept method execution on a proxy object. It allows entering before method invocations, exiting after method executions, and handling errors during method execution for monitoring or altering behavior.

type MethodInterceptor interface {
    Interceptor
    Enter(target any, methodName string, parameters []ParameterInfo)
    Exit(target any, methodName string, returnValues []ReturnValueInfo)
    OnError(target any, methodName string, err error)
}

# type MockBase

MockBase is used as a foundational struct to track and manage mocked functions and their call history. It helps in testing by allowing function signature tracking and call verification.

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

# func NewMockBase

func NewMockBase() MockBase

NewMockBase initializes and returns an instance of MockBase, ideal for setting up and using mock functions in tests.

# func (*MockBase) AddFunction

func (m *MockBase) AddFunction(name string, signature string)

AddFunction adds a new mock function with the specified name and signature to the MockBase instance.

# func (*MockBase) TraceMethodCall

func (m *MockBase) TraceMethodCall(name string, arguments ...any)

TraceMethodCall logs the invocation of a mocked function with specified arguments to facilitate function call tracking during testing. Before function calls can be tracked, the function must be registered with the MockBase instance; use AddFunction.

# func (*MockBase) Verify

func (m *MockBase) Verify(name string, times TimesFunc, matches ...ArgMatch) bool

Verify checks if a mock function was called a specific number of times, optionally matching provided argument conditions.

# type MockFunction

MockFunction provides a structure to represent a mocked function in test scenarios. It allows tracking its calls and signature.

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

# func (MockFunction) String

func (m MockFunction) String() string

String returns the signature of the mocked function if it exists, otherwise it returns the function's name.

# type ParameterInfo

ParameterInfo represents information about a method parameter, including its value, type, and name. It is used in method interception where parameters need to be inspected or logged.

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

# func (ParameterInfo) String

func (p ParameterInfo) String() string

String returns a formatted string representation of the ParameterInfo, useful for logging and debugging purposes.

# type ProxyBase

ProxyBase facilitates method interception by allowing the inclusion of multiple interceptors to target method calls. Typically used to monitor, log, or modify behavior of an object's method execution.

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

# func NewProxyBase

func NewProxyBase[T any](target T, interceptors []MethodInterceptor) ProxyBase

NewProxyBase creates a ProxyBase instance with the provided target and a sorted list of method interceptors. Useful for setting up method interception on the target object.

# func (*ProxyBase) InvokeEnterMethodInterceptors

func (p *ProxyBase) InvokeEnterMethodInterceptors(callContext *MethodCallContext)

InvokeEnterMethodInterceptors triggers the Enter method on all registered interceptors before the target method executes.

# func (*ProxyBase) InvokeExitMethodInterceptors

func (p *ProxyBase) InvokeExitMethodInterceptors(callContext *MethodCallContext)

InvokeExitMethodInterceptors triggers the Exit method of all registered interceptors after the target method completes.

# func (*ProxyBase) InvokeMethodErrorInterceptors

func (p *ProxyBase) InvokeMethodErrorInterceptors(callContext *MethodCallContext, returnValues ...interface{})

InvokeMethodErrorInterceptors intercepts the return values of a method, checks for errors, and triggers OnError for registered interceptors.

# type ReturnValueInfo

ReturnValueInfo represents the value and type information of a method's return value, used in method interception.

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

# func (ReturnValueInfo) String

func (r ReturnValueInfo) String() string

String returns a string representation of ReturnValueInfo, formatting the value and its type for debugging purposes.

# type TimesFunc

TimesFunc is used to verify the number of times a mock function is called. It allows flexibility in call count assertions.

type TimesFunc func(times int) bool

# func TimesAtLeastOnce

func TimesAtLeastOnce() TimesFunc

TimesAtLeastOnce returns a TimesFunc that verifies if a mock function is called at least once.

# func TimesExactly

func TimesExactly(n int) TimesFunc

TimesExactly returns a TimesFunc that checks if the number of function calls is exactly equal to the specified value.

# func TimesNever

func TimesNever() TimesFunc

TimesNever returns a TimesFunc that ensures the function has never been called, providing a strict zero call condition.

# func TimesOnce

func TimesOnce() TimesFunc

TimesOnce returns a TimesFunc that checks if the number of function calls equals one. It is useful for verifying single call assertions.