Documentation
¶
Index ¶
- func GenerateDetectionIDs(count int) []string
- func GenerateDeviceIDs(count int) []string
- func GetParamsAs[T any](request Request) (*T, bool)
- func MatchesOperation(request Request, operationID string) bool
- func NewMockClient() *client.CrowdStrikeAPISpecification
- type FakeClient
- func (fc *FakeClient) AddErrorMockHandler(operationID string, err error)
- func (fc *FakeClient) AddMockHandler(operationID string, handler MockHandlerFunc)
- func (fc *FakeClient) AddStaticMockHandler(operationID string, response interface{})
- func (fc *FakeClient) ClearRequests()
- func (fc *FakeClient) CountRequests(operationID string) int
- func (fc *FakeClient) FilterRequests(operationID string) []Request
- func (fc *FakeClient) GetClient() *client.CrowdStrikeAPISpecification
- func (fc *FakeClient) PrependMockHandler(operationID string, handler MockHandlerFunc)
- func (fc *FakeClient) ProcessRequest(request Request, defaultReturnObj interface{}) (interface{}, error)
- func (fc *FakeClient) Requests() []Request
- func (fc *FakeClient) Reset()
- func (fc *FakeClient) SetDefaultHandler(handler MockHandlerFunc)
- type FakeTransport
- type MockHandler
- type MockHandlerFunc
- type Request
- type RequestImpl
- type SimpleMockHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateDetectionIDs ¶
GenerateDetectionIDs generates a slice of deterministic detection IDs for testing. IDs are 32-character lowercase hex strings resembling real CrowdStrike detection IDs.
func GenerateDeviceIDs ¶
GenerateDeviceIDs generates a slice of deterministic device IDs for testing. IDs are 32-character lowercase hex strings resembling real CrowdStrike device IDs.
func GetParamsAs ¶
GetParamsAs attempts to cast the request's parameters to the specified type. This is a helper for mock handlers that need to inspect parameters.
func MatchesOperation ¶
MatchesOperation returns true if the request matches the specified operation ID.
func NewMockClient ¶
func NewMockClient() *client.CrowdStrikeAPISpecification
NewMockClient returns a fully-wired CrowdStrikeAPISpecification where every service panics with a clear message if called without being replaced. Swap individual service fields with your own ClientService interface mocks for the services under test.
Example:
mc := faketest.NewMockClient()
mc.Hosts = &myMockHosts{...} // only mock what you test
result, err := mc.Hosts.QueryDevicesByFilter(params)
Types ¶
type FakeClient ¶
type FakeClient struct {
sync.RWMutex
// HandlerChain is the list of mock handlers that will be attempted for every
// request in the order they are tried.
HandlerChain []MockHandler
// contains filtered or unexported fields
}
FakeClient provides a fake implementation of the CrowdStrike API client for testing. It uses a mock handler pattern similar to Kubernetes' fake client to allow configurable responses.
func NewFakeClient ¶
func NewFakeClient() *FakeClient
NewFakeClient creates a new fake CrowdStrike API client for testing.
func NewFakeClientFromConfig ¶
func NewFakeClientFromConfig() *FakeClient
NewFakeClientFromConfig creates a fake client that can be used as a drop-in replacement for falcon.NewClient(). Call GetClient() to obtain the underlying API client.
func (*FakeClient) AddErrorMockHandler ¶
func (fc *FakeClient) AddErrorMockHandler(operationID string, err error)
AddErrorMockHandler adds a mock handler that always returns the specified error.
func (*FakeClient) AddMockHandler ¶
func (fc *FakeClient) AddMockHandler(operationID string, handler MockHandlerFunc)
AddMockHandler appends a mock handler to the end of the chain.
func (*FakeClient) AddStaticMockHandler ¶
func (fc *FakeClient) AddStaticMockHandler(operationID string, response interface{})
AddStaticMockHandler adds a mock handler that always returns the same static response.
func (*FakeClient) ClearRequests ¶
func (fc *FakeClient) ClearRequests()
ClearRequests clears the history of requests called on the fake client.
func (*FakeClient) CountRequests ¶
func (fc *FakeClient) CountRequests(operationID string) int
CountRequests returns the number of requests matching the specified operation ID.
func (*FakeClient) FilterRequests ¶
func (fc *FakeClient) FilterRequests(operationID string) []Request
FilterRequests returns requests that match the specified operation ID.
func (*FakeClient) GetClient ¶
func (fc *FakeClient) GetClient() *client.CrowdStrikeAPISpecification
GetClient returns the underlying CrowdStrike API client.
func (*FakeClient) PrependMockHandler ¶
func (fc *FakeClient) PrependMockHandler(operationID string, handler MockHandlerFunc)
PrependMockHandler adds a mock handler to the beginning of the chain.
func (*FakeClient) ProcessRequest ¶
func (fc *FakeClient) ProcessRequest(request Request, defaultReturnObj interface{}) (interface{}, error)
ProcessRequest processes an API operation through the mock handler chain. This is called by the FakeTransport when API operations are executed.
func (*FakeClient) Requests ¶
func (fc *FakeClient) Requests() []Request
Requests returns a chronologically ordered slice of requests called on the fake client.
func (*FakeClient) Reset ¶
func (fc *FakeClient) Reset()
Reset clears all requests and mock handlers, returning the client to initial state.
func (*FakeClient) SetDefaultHandler ¶
func (fc *FakeClient) SetDefaultHandler(handler MockHandlerFunc)
SetDefaultHandler sets a catch-all handler that matches any operation not handled by more specific handlers. It appends to the end of the handler chain.
type FakeTransport ¶
type FakeTransport struct {
// contains filtered or unexported fields
}
FakeTransport implements runtime.ClientTransport for the fake client. It intercepts all API operations and routes them through the fake client's mock handler chain.
func (*FakeTransport) Submit ¶
func (ft *FakeTransport) Submit(op *runtime.ClientOperation) (interface{}, error)
Submit implements runtime.ClientTransport.Submit().
type MockHandler ¶
type MockHandler interface {
// Handles indicates whether this MockHandler deals with a given operation.
Handles(request Request) bool
// Handle processes the operation and returns results. It may choose to
// delegate by indicating handled=false.
Handle(request Request) (handled bool, ret interface{}, err error)
}
MockHandler is an interface to allow composition of mock response functions for API operations.
type MockHandlerFunc ¶
MockHandlerFunc is a function that returns a response for a given Request. If "handled" is false, the fake client will continue to the next MockHandlerFunc.
type Request ¶
type Request interface {
// GetOperationID returns the OpenAPI operation ID (e.g., "QueryDevicesByFilter")
GetOperationID() string
// GetParams returns the operation parameters
GetParams() interface{}
// GetTimestamp returns when the request was created
GetTimestamp() time.Time
// DeepCopy creates a copy of the request to avoid mutation
DeepCopy() Request
}
Request represents an API operation call with its parameters and metadata.
func NewRequest ¶
NewRequest creates a new Request for testing purposes.
type RequestImpl ¶
RequestImpl provides a basic implementation of the Request interface.
func (RequestImpl) DeepCopy ¶
func (r RequestImpl) DeepCopy() Request
func (RequestImpl) GetOperationID ¶
func (r RequestImpl) GetOperationID() string
func (RequestImpl) GetParams ¶
func (r RequestImpl) GetParams() interface{}
func (RequestImpl) GetTimestamp ¶
func (r RequestImpl) GetTimestamp() time.Time
type SimpleMockHandler ¶
type SimpleMockHandler struct {
OperationID string
Handler MockHandlerFunc
}
SimpleMockHandler provides a basic mock handler implementation that matches operations by ID.
func (*SimpleMockHandler) Handle ¶
func (h *SimpleMockHandler) Handle(request Request) (bool, interface{}, error)
func (*SimpleMockHandler) Handles ¶
func (h *SimpleMockHandler) Handles(request Request) bool