Documentation
¶
Overview ¶
Package itestkit is a generated GoMock package.
Package itestkit is a portable core for running integration tests on JSONC cases.
Index ¶
- Constants
- func DecodeExpectedJSON(raw json.RawMessage) (any, error)
- func DecodeStrictJSON(raw json.RawMessage, target any) error
- func MatchExpectedJSON(expected, actual any, mode MatchMode) error
- func RunCases[SC any, C any, S comparable](t *testing.T, cases []Case[C, S], lifecycle SuiteLifecycle[SC], ...)
- type Assert
- type AwaitRetry
- type Case
- type CaseSource
- type ErrorInspector
- type Handler
- type HandlerRegistry
- type HarnessFactory
- type MapRegistry
- type MatchMode
- type MockCaseSource
- type MockCaseSourceMockRecorder
- type MockErrorInspector
- type MockErrorInspectorMockRecorder
- type MockHandler
- func (m *MockHandler[C]) DecodeExpectedResponse(raw json.RawMessage) (any, error)
- func (m *MockHandler[C]) DecodeRequest(raw json.RawMessage) (any, error)
- func (m *MockHandler[C]) EXPECT() *MockHandlerMockRecorder[C]
- func (m *MockHandler[C]) Invoke(ctx context.Context, client C, request any) (any, error)
- func (m *MockHandler[C]) NormalizeResponse(response any) (any, error)
- type MockHandlerMockRecorder
- func (mr *MockHandlerMockRecorder[C]) DecodeExpectedResponse(raw any) *gomock.Call
- func (mr *MockHandlerMockRecorder[C]) DecodeRequest(raw any) *gomock.Call
- func (mr *MockHandlerMockRecorder[C]) Invoke(ctx, client, request any) *gomock.Call
- func (mr *MockHandlerMockRecorder[C]) NormalizeResponse(response any) *gomock.Call
- type MockHandlerRegistry
- type MockHandlerRegistryMockRecorder
- type MockHarnessFactory
- type MockHarnessFactoryMockRecorder
- type MockStatusCodec
- type MockStatusCodecMockRecorder
- type MockSuiteCaseHarnessFactory
- type MockSuiteCaseHarnessFactoryMockRecorder
- type MockSuiteLifecycle
- type MockSuiteLifecycleMockRecorder
- type ResponseMode
- type RunCasesOption
- type StatusCodec
- type Step
- type StepKind
- type SuiteCaseHarnessFactory
- type SuiteLifecycle
Constants ¶
const ( // DefaultParallelCasesLimit sets the default limit of parallel cases when parallel mode is enabled. DefaultParallelCasesLimit = 10 // DefaultJSONDiffContextLines specifies the number of context lines in the JSON-like diff output. DefaultJSONDiffContextLines = 3 )
Variables ¶
This section is empty.
Functions ¶
func DecodeExpectedJSON ¶ added in v1.4.1
func DecodeExpectedJSON(raw json.RawMessage) (any, error)
DecodeExpectedJSON decodes expected JSON while preserving matcher objects and JSON numbers.
func DecodeStrictJSON ¶
func DecodeStrictJSON(raw json.RawMessage, target any) error
DecodeStrictJSON decodes JSON without unknown fields and trailing data.
This aligns the behavior of custom handlers with the underlying `itestkit` guarantees and removes duplication of the same strict decode code between packages.
func MatchExpectedJSON ¶ added in v1.4.1
MatchExpectedJSON compares expected JSON with actual JSON-safe data using marker-aware rules.
func RunCases ¶
func RunCases[SC any, C any, S comparable]( t *testing.T, cases []Case[C, S], lifecycle SuiteLifecycle[SC], caseFactory SuiteCaseHarnessFactory[SC, C], inspector ErrorInspector[S], statusCodec StatusCodec[S], options ...RunCasesOption, )
RunCases executes a set of cases through a suite lifecycle (setup once / teardown once).
Types ¶
type Assert ¶
type Assert[S comparable] struct { Code S MessageContains string Response any ResponseFromStep string ResponseMode ResponseMode }
Assert stores the expected status and expected response for a successful scenario.
type AwaitRetry ¶
AwaitRetry describes the retry policy for the kind=await step.
type Case ¶
type Case[C any, S comparable] struct { Name string SourcePath string Steps []Step[C] Assert Assert[S] }
Case describes a loaded integration case.
func LoadCases ¶
func LoadCases[C any, S comparable]( source CaseSource, rootDir string, registry HandlerRegistry[C], statusCodec StatusCodec[S], ) ([]Case[C, S], error)
LoadCases loads and validates cases from the source.
type CaseSource ¶
type CaseSource interface {
ReadDir(name string) ([]fs.DirEntry, error)
ReadFile(name string) ([]byte, error)
}
CaseSource describes a source for reading a tree of cases and files.
type ErrorInspector ¶
type ErrorInspector[S comparable] interface { // FromError returns the status, message, and flag whether the status was retrieved successfully. FromError(err error) (code S, message string, ok bool) }
ErrorInspector extracts the status and message from the transport error.
type Handler ¶
type Handler[C any] interface { // DecodeRequest converts the raw JSON of the request to the type expected by the handler. DecodeRequest(raw json.RawMessage) (any, error) // DecodeExpectedResponse converts the raw JSON of the response to the type expected by the comparison. DecodeExpectedResponse(raw json.RawMessage) (any, error) // Invoke invokes a handler with a prepared request. Invoke(ctx context.Context, client C, request any) (any, error) // NormalizeResponse brings the response into a stable form for comparison. NormalizeResponse(response any) (any, error) }
Handler is responsible for decoding the payload, calling the handler and normalizing the response.
type HandlerRegistry ¶
type HandlerRegistry[C any] interface { // Resolve returns a handler by name. Resolve(name string) (Handler[C], error) // Supported returns a list of supported handler names. Supported() []string }
HandlerRegistry resolves handlers by name and reports supported names.
type HarnessFactory ¶
type HarnessFactory[C any] interface { // New creates a new client for case execution. New(t *testing.T) C }
HarnessFactory creates an isolated client/environment for each case.
type MapRegistry ¶
type MapRegistry[C any] struct { // contains filtered or unexported fields }
MapRegistry stores step handlers and implements HandlerRegistry.
func NewMapRegistry ¶
func NewMapRegistry[C any](handlers map[string]Handler[C]) MapRegistry[C]
NewMapRegistry creates a map-based handler registry with protective copying.
func (MapRegistry[C]) Resolve ¶
func (registry MapRegistry[C]) Resolve(name string) (Handler[C], error)
Resolve returns a handler by name.
func (MapRegistry[C]) Supported ¶
func (registry MapRegistry[C]) Supported() []string
Supported returns a sorted list of supported handlers.
type MatchMode ¶ added in v1.4.1
type MatchMode string
MatchMode selects how expected JSON is compared with actual JSON-safe data.
type MockCaseSource ¶
type MockCaseSource struct {
// contains filtered or unexported fields
}
MockCaseSource is a mock of CaseSource interface.
func NewMockCaseSource ¶
func NewMockCaseSource(ctrl *gomock.Controller) *MockCaseSource
NewMockCaseSource creates a new mock instance.
func (*MockCaseSource) EXPECT ¶
func (m *MockCaseSource) EXPECT() *MockCaseSourceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockCaseSourceMockRecorder ¶
type MockCaseSourceMockRecorder struct {
// contains filtered or unexported fields
}
MockCaseSourceMockRecorder is the mock recorder for MockCaseSource.
type MockErrorInspector ¶
type MockErrorInspector[S comparable] struct { // contains filtered or unexported fields }
MockErrorInspector is a mock of ErrorInspector interface.
func NewMockErrorInspector ¶
func NewMockErrorInspector[S comparable](ctrl *gomock.Controller) *MockErrorInspector[S]
NewMockErrorInspector creates a new mock instance.
func (*MockErrorInspector[S]) EXPECT ¶
func (m *MockErrorInspector[S]) EXPECT() *MockErrorInspectorMockRecorder[S]
EXPECT returns an object that allows the caller to indicate expected use.
type MockErrorInspectorMockRecorder ¶
type MockErrorInspectorMockRecorder[S comparable] struct { // contains filtered or unexported fields }
MockErrorInspectorMockRecorder is the mock recorder for MockErrorInspector.
type MockHandler ¶
type MockHandler[C any] struct { // contains filtered or unexported fields }
MockHandler is a mock of Handler interface.
func NewMockHandler ¶
func NewMockHandler[C any](ctrl *gomock.Controller) *MockHandler[C]
NewMockHandler creates a new mock instance.
func (*MockHandler[C]) DecodeExpectedResponse ¶
func (m *MockHandler[C]) DecodeExpectedResponse(raw json.RawMessage) (any, error)
DecodeExpectedResponse mocks base method.
func (*MockHandler[C]) DecodeRequest ¶
func (m *MockHandler[C]) DecodeRequest(raw json.RawMessage) (any, error)
DecodeRequest mocks base method.
func (*MockHandler[C]) EXPECT ¶
func (m *MockHandler[C]) EXPECT() *MockHandlerMockRecorder[C]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockHandler[C]) NormalizeResponse ¶
func (m *MockHandler[C]) NormalizeResponse(response any) (any, error)
NormalizeResponse mocks base method.
type MockHandlerMockRecorder ¶
type MockHandlerMockRecorder[C any] struct { // contains filtered or unexported fields }
MockHandlerMockRecorder is the mock recorder for MockHandler.
func (*MockHandlerMockRecorder[C]) DecodeExpectedResponse ¶
func (mr *MockHandlerMockRecorder[C]) DecodeExpectedResponse(raw any) *gomock.Call
DecodeExpectedResponse indicates an expected call of DecodeExpectedResponse.
func (*MockHandlerMockRecorder[C]) DecodeRequest ¶
func (mr *MockHandlerMockRecorder[C]) DecodeRequest(raw any) *gomock.Call
DecodeRequest indicates an expected call of DecodeRequest.
func (*MockHandlerMockRecorder[C]) Invoke ¶
func (mr *MockHandlerMockRecorder[C]) Invoke(ctx, client, request any) *gomock.Call
Invoke indicates an expected call of Invoke.
func (*MockHandlerMockRecorder[C]) NormalizeResponse ¶
func (mr *MockHandlerMockRecorder[C]) NormalizeResponse(response any) *gomock.Call
NormalizeResponse indicates an expected call of NormalizeResponse.
type MockHandlerRegistry ¶
type MockHandlerRegistry[C any] struct { // contains filtered or unexported fields }
MockHandlerRegistry is a mock of HandlerRegistry interface.
func NewMockHandlerRegistry ¶
func NewMockHandlerRegistry[C any](ctrl *gomock.Controller) *MockHandlerRegistry[C]
NewMockHandlerRegistry creates a new mock instance.
func (*MockHandlerRegistry[C]) EXPECT ¶
func (m *MockHandlerRegistry[C]) EXPECT() *MockHandlerRegistryMockRecorder[C]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockHandlerRegistry[C]) Resolve ¶
func (m *MockHandlerRegistry[C]) Resolve(name string) (Handler[C], error)
Resolve mocks base method.
func (*MockHandlerRegistry[C]) Supported ¶
func (m *MockHandlerRegistry[C]) Supported() []string
Supported mocks base method.
type MockHandlerRegistryMockRecorder ¶
type MockHandlerRegistryMockRecorder[C any] struct { // contains filtered or unexported fields }
MockHandlerRegistryMockRecorder is the mock recorder for MockHandlerRegistry.
func (*MockHandlerRegistryMockRecorder[C]) Resolve ¶
func (mr *MockHandlerRegistryMockRecorder[C]) Resolve(name any) *gomock.Call
Resolve indicates an expected call of Resolve.
func (*MockHandlerRegistryMockRecorder[C]) Supported ¶
func (mr *MockHandlerRegistryMockRecorder[C]) Supported() *gomock.Call
Supported indicates an expected call of Supported.
type MockHarnessFactory ¶
type MockHarnessFactory[C any] struct { // contains filtered or unexported fields }
MockHarnessFactory is a mock of HarnessFactory interface.
func NewMockHarnessFactory ¶
func NewMockHarnessFactory[C any](ctrl *gomock.Controller) *MockHarnessFactory[C]
NewMockHarnessFactory creates a new mock instance.
func (*MockHarnessFactory[C]) EXPECT ¶
func (m *MockHarnessFactory[C]) EXPECT() *MockHarnessFactoryMockRecorder[C]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockHarnessFactory[C]) New ¶
func (m *MockHarnessFactory[C]) New(t *testing.T) C
New mocks base method.
type MockHarnessFactoryMockRecorder ¶
type MockHarnessFactoryMockRecorder[C any] struct { // contains filtered or unexported fields }
MockHarnessFactoryMockRecorder is the mock recorder for MockHarnessFactory.
type MockStatusCodec ¶
type MockStatusCodec[S comparable] struct { // contains filtered or unexported fields }
MockStatusCodec is a mock of StatusCodec interface.
func NewMockStatusCodec ¶
func NewMockStatusCodec[S comparable](ctrl *gomock.Controller) *MockStatusCodec[S]
NewMockStatusCodec creates a new mock instance.
func (*MockStatusCodec[S]) EXPECT ¶
func (m *MockStatusCodec[S]) EXPECT() *MockStatusCodecMockRecorder[S]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockStatusCodec[S]) Parse ¶
func (m *MockStatusCodec[S]) Parse(raw string) (S, error)
Parse mocks base method.
func (*MockStatusCodec[S]) Success ¶
func (m *MockStatusCodec[S]) Success() S
Success mocks base method.
type MockStatusCodecMockRecorder ¶
type MockStatusCodecMockRecorder[S comparable] struct { // contains filtered or unexported fields }
MockStatusCodecMockRecorder is the mock recorder for MockStatusCodec.
func (*MockStatusCodecMockRecorder[S]) Parse ¶
func (mr *MockStatusCodecMockRecorder[S]) Parse(raw any) *gomock.Call
Parse indicates an expected call of Parse.
func (*MockStatusCodecMockRecorder[S]) Success ¶
func (mr *MockStatusCodecMockRecorder[S]) Success() *gomock.Call
Success indicates an expected call of Success.
type MockSuiteCaseHarnessFactory ¶
type MockSuiteCaseHarnessFactory[SC any, C any] struct { // contains filtered or unexported fields }
MockSuiteCaseHarnessFactory is a mock of SuiteCaseHarnessFactory interface.
func NewMockSuiteCaseHarnessFactory ¶
func NewMockSuiteCaseHarnessFactory[SC any, C any](ctrl *gomock.Controller) *MockSuiteCaseHarnessFactory[SC, C]
NewMockSuiteCaseHarnessFactory creates a new mock instance.
func (*MockSuiteCaseHarnessFactory[SC, C]) EXPECT ¶
func (m *MockSuiteCaseHarnessFactory[SC, C]) EXPECT() *MockSuiteCaseHarnessFactoryMockRecorder[SC, C]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockSuiteCaseHarnessFactory[SC, C]) NewCaseHarness ¶
func (m *MockSuiteCaseHarnessFactory[SC, C]) NewCaseHarness(t *testing.T, suiteContext SC) C
NewCaseHarness mocks base method.
type MockSuiteCaseHarnessFactoryMockRecorder ¶
type MockSuiteCaseHarnessFactoryMockRecorder[SC any, C any] struct { // contains filtered or unexported fields }
MockSuiteCaseHarnessFactoryMockRecorder is the mock recorder for MockSuiteCaseHarnessFactory.
func (*MockSuiteCaseHarnessFactoryMockRecorder[SC, C]) NewCaseHarness ¶
func (mr *MockSuiteCaseHarnessFactoryMockRecorder[SC, C]) NewCaseHarness(t, suiteContext any) *gomock.Call
NewCaseHarness indicates an expected call of NewCaseHarness.
type MockSuiteLifecycle ¶
type MockSuiteLifecycle[SC any] struct { // contains filtered or unexported fields }
MockSuiteLifecycle is a mock of SuiteLifecycle interface.
func NewMockSuiteLifecycle ¶
func NewMockSuiteLifecycle[SC any](ctrl *gomock.Controller) *MockSuiteLifecycle[SC]
NewMockSuiteLifecycle creates a new mock instance.
func (*MockSuiteLifecycle[SC]) EXPECT ¶
func (m *MockSuiteLifecycle[SC]) EXPECT() *MockSuiteLifecycleMockRecorder[SC]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockSuiteLifecycle[SC]) SetupSuite ¶
func (m *MockSuiteLifecycle[SC]) SetupSuite(t *testing.T) (SC, error)
SetupSuite mocks base method.
func (*MockSuiteLifecycle[SC]) TeardownSuite ¶
func (m *MockSuiteLifecycle[SC]) TeardownSuite(t *testing.T, suiteContext SC) error
TeardownSuite mocks base method.
type MockSuiteLifecycleMockRecorder ¶
type MockSuiteLifecycleMockRecorder[SC any] struct { // contains filtered or unexported fields }
MockSuiteLifecycleMockRecorder is the mock recorder for MockSuiteLifecycle.
func (*MockSuiteLifecycleMockRecorder[SC]) SetupSuite ¶
func (mr *MockSuiteLifecycleMockRecorder[SC]) SetupSuite(t any) *gomock.Call
SetupSuite indicates an expected call of SetupSuite.
func (*MockSuiteLifecycleMockRecorder[SC]) TeardownSuite ¶
func (mr *MockSuiteLifecycleMockRecorder[SC]) TeardownSuite(t, suiteContext any) *gomock.Call
TeardownSuite indicates an expected call of TeardownSuite.
type ResponseMode ¶
type ResponseMode string
ResponseMode specifies how a successful response is compared.
const ( // ResponseModeExact requires an exact match of the normalized response. ResponseModeExact ResponseMode = "exact" // ResponseModePartial only checks the fields listed in assert.response. ResponseModePartial ResponseMode = "partial" )
type RunCasesOption ¶
type RunCasesOption func(*runCasesConfig)
RunCasesOption configures the behavior of RunCases.
func WithContinueOnFailure ¶
func WithContinueOnFailure() RunCasesOption
WithContinueOnFailure disables fail-fast and runs all cases to completion.
func WithParallelCases ¶
func WithParallelCases() RunCasesOption
WithParallelCases enables parallel running of cases. The limit of parallel cases can be configured via WithParallelismLimit. By default, the limit is DefaultParallelCasesLimit.
func WithParallelismLimit ¶
func WithParallelismLimit(limit int) RunCasesOption
WithParallelismLimit sets the limit of parallel cases and enables parallel mode.
type StatusCodec ¶
type StatusCodec[S comparable] interface { // Parse converts the string code into a status type. Parse(raw string) (S, error) // Success returns the success code. Success() S }
StatusCodec parses the status code and provides a success code.
type Step ¶
type Step[C any] struct { ID string Kind StepKind HandlerName string Handler Handler[C] Request any Retry *AwaitRetry }
Step stores the handler and the prepared request.
type StepKind ¶
type StepKind string
StepKind describes the type of step in the unified step-based model.
const ( StepKindPrepare StepKind = "prepare" StepKindAction StepKind = "action" StepKindPublish StepKind = "publish" StepKindAwait StepKind = "await" StepKindVerify StepKind = "verify" StepKindCleanup StepKind = "cleanup" )
StepKind* constants define all supported step kinds in unified step-based execution.
type SuiteCaseHarnessFactory ¶
type SuiteCaseHarnessFactory[SC any, C any] interface { // NewCaseHarness creates a case-level harness using the prepared suite context. NewCaseHarness(t *testing.T, suiteContext SC) C }
SuiteCaseHarnessFactory creates a per-case harness based on the suite context.
type SuiteLifecycle ¶
type SuiteLifecycle[SC any] interface { // SetupSuite prepares the suite environment once per set of cases. SetupSuite(t *testing.T) (SC, error) // TeardownSuite releases the suite environment after the set of cases is completed. TeardownSuite(t *testing.T, suiteContext SC) error }
SuiteLifecycle manages the life cycle of a suite environment.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
docs
|
|
|
itestkit/examples/bookingcalendar
Package bookingcalendar demonstrates calendar-aware JSONC fixtures with a fixed application clock.
|
Package bookingcalendar demonstrates calendar-aware JSONC fixtures with a fixed application clock. |
|
itestkit/examples/custom
Package custom shows a minimal itestkit usage example without gRPC.
|
Package custom shows a minimal itestkit usage example without gRPC. |
|
itestkit/examples/extapiasync
Package extapiasync demonstrates an async external API call scenario via an await step.
|
Package extapiasync demonstrates an async external API call scenario via an await step. |
|
itestkit/examples/extapisync
Package extapisync demonstrates a synchronous external API call scenario in a step pipeline.
|
Package extapisync demonstrates a synchronous external API call scenario in a step pipeline. |
|
itestkit/examples/grpc
Package grpc shows a minimal itestkit usage example with gRPC.
|
Package grpc shows a minimal itestkit usage example with gRPC. |
|
itestkit/examples/httpserver
Package httpserverexample shows JSONC-driven tests for an in-process HTTP API.
|
Package httpserverexample shows JSONC-driven tests for an in-process HTTP API. |
|
itestkit/examples/queue/inbound
Package queue demonstrates an event-style scenario with an in-memory queue and DB.
|
Package queue demonstrates an event-style scenario with an in-memory queue and DB. |
|
itestkit/examples/queue/outbound
Package kafkaoutbound demonstrates a ready-to-use outbound Kafka preset for JSONC cases.
|
Package kafkaoutbound demonstrates a ready-to-use outbound Kafka preset for JSONC cases. |
|
itestkit/examples/real/service
Package service contains an example of a production-like gRPC service for integration tests.
|
Package service contains an example of a production-like gRPC service for integration tests. |
|
Package grpc contains gRPC-specific implementations for itestkit.
|
Package grpc contains gRPC-specific implementations for itestkit. |
|
Package httpmock provides JSONC-driven outbound HTTP mocks for itestkit cases.
|
Package httpmock provides JSONC-driven outbound HTTP mocks for itestkit cases. |
|
Package httpserver provides itestkit handlers for in-process HTTP servers.
|
Package httpserver provides itestkit handlers for in-process HTTP servers. |
|
internal
|
|
|
jsonsubset
Package jsonsubset provides structural JSON subset matching for internal helpers.
|
Package jsonsubset provides structural JSON subset matching for internal helpers. |
|
protojsonview
Package protojsonview converts protobuf messages into JSON-like values.
|
Package protojsonview converts protobuf messages into JSON-like values. |
|
queue
|
|
|
itest
Package itest contains ready-made preset handlers for outbound checks in the itestkit pipeline.
|
Package itest contains ready-made preset handlers for outbound checks in the itestkit pipeline. |
|
kafkaproducer
Package kafkaproducer is a generated GoMock package.
|
Package kafkaproducer is a generated GoMock package. |
|
probe
Package probe contains a transport-agnostic contract and a matcher for checking outbound messages.
|
Package probe contains a transport-agnostic contract and a matcher for checking outbound messages. |
|
Package testcalendar provides a fixed calendar and substitution of calendar macros for integration tests.
|
Package testcalendar provides a fixed calendar and substitution of calendar macros for integration tests. |