itestkit

package module
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 27 Imported by: 0

README

itestkit

itestkit runs integration tests from JSONC files.

It is useful when many integration scenarios have the same execution shape but different input and expected output. Test code wires your service once. JSONC cases describe the scenarios.

The core runner does not know anything about your service, transport, database, or message broker. You connect it through small interfaces: handlers execute steps, a lifecycle prepares shared resources, and a status codec maps fixture status strings to your status type.

When to use it

Use itestkit when you want to:

  • keep integration scenarios as readable JSONC fixtures;
  • run the same runner against HTTP, gRPC, queue, or custom service calls;
  • describe multi-step flows with setup, actions, polling, verification, and cleanup;
  • compare normalized responses in exact or partial mode;
  • reuse one suite setup for many cases.

Install

go get github.com/n-r-w/itestkit

Requires Go 1.26.0 or newer.

Quick start

  1. Put cases into .jsonc files.
  2. Implement handlers for the operations used by those cases.
  3. Register handlers by name.
  4. Load cases with itestkit.LoadCases.
  5. Run them with itestkit.RunCases.
func TestIntegration(t *testing.T) {
    t.Parallel()

    codec := statusCodec{}
    registry := itestkit.NewMapRegistry(map[string]itestkit.Handler[*Client]{
        "CreateOrder": createOrderHandler{},
        "GetOrder":    getOrderHandler{},
    })

    cases, err := itestkit.LoadCases(casesFS, "cases", registry, codec)
    require.NoError(t, err)

    itestkit.RunCases(
        t,
        cases,
        suiteLifecycle{},
        caseHarnessFactory{},
        errorInspector{},
        codec,
    )
}

casesFS can be embed.FS or another source that implements ReadDir and ReadFile.

Case format

A case contains a name, ordered steps, and an expected result.

{
  "name": "create and read order",
  "steps": [
    {
      "id": "create",
      "kind": "action",
      "handler": "CreateOrder",
      "request": {
        "order_id": "order-1",
        "amount": 1000
      }
    },
    {
      "id": "read",
      "kind": "verify",
      "handler": "GetOrder",
      "request": {
        "order_id": "order-1"
      }
    }
  ],
  "assert": {
    "code": "OK",
    "response_from_step": "read",
    "response_mode": "partial",
    "response": {
      "order_id": "order-1",
      "amount": 1000
    }
  }
}

Supported step kinds:

  • prepare — prepare data or environment before the main action;
  • action — call the operation under test;
  • publish — send an event or message;
  • await — retry a check until it succeeds or the retry policy is exhausted;
  • verify — check side effects or final state;
  • cleanup — clean resources after the case; cleanup steps still run after earlier step errors.

For await, add a retry policy:

{
  "id": "wait-for-processing",
  "kind": "await",
  "handler": "AwaitOrderProcessed",
  "request": { "order_id": "order-1" },
  "retry": {
    "timeout_ms": 5000,
    "interval_ms": 100,
    "max_attempts": 50
  }
}

A step request can use a response from an earlier step:

{
  "id": "read-created-order",
  "kind": "verify",
  "handler": "GetOrder",
  "request": {
    "order_id": "{{steps.create.response.order_id}}"
  }
}

What you implement

Handler

A handler binds one fixture operation to your code.

type createOrderHandler struct{}

func (createOrderHandler) DecodeRequest(raw json.RawMessage) (any, error) {
    var request CreateOrderRequest
    if err := itestkit.DecodeStrictJSON(raw, &request); err != nil {
        return nil, err
    }
    return &request, nil
}

func (createOrderHandler) DecodeExpectedResponse(raw json.RawMessage) (any, error) {
    var response OrderResponse
    if err := itestkit.DecodeStrictJSON(raw, &response); err != nil {
        return nil, err
    }
    return &response, nil
}

func (createOrderHandler) Invoke(ctx context.Context, client *Client, request any) (any, error) {
    typedRequest, ok := request.(*CreateOrderRequest)
    if !ok {
        return nil, fmt.Errorf("CreateOrder received invalid request type: %T", request)
    }
    return client.CreateOrder(ctx, typedRequest)
}

func (createOrderHandler) NormalizeResponse(response any) (any, error) {
    return response, nil
}

NormalizeResponse should return a stable value for comparison. Use it to remove volatile fields or convert transport-specific responses to simple Go values.

Suite and case lifecycle

RunCases separates suite setup from per-case setup.

  • SuiteLifecycle starts and stops shared resources once for the whole case set.
  • SuiteCaseHarnessFactory creates the client or harness for one case.
  • ErrorInspector converts runtime errors to the same status type that fixtures use.
  • StatusCodec parses assert.code and returns the success status.

Assertions

assert.code is always checked.

For successful cases, assert.response is checked against a normalized step response. If response_from_step is empty, itestkit uses the last action step.

response_mode values:

  • exact — the full normalized response must match. Use { "$present": true } as an object field value to assert that the field exists with any value. The marker is not valid at the root or as an array element. A present field with null passes.
  • partial — object fields from assert.response must match, and extra object fields in the actual response are allowed. Use { "$present": true } with the same rules as in exact. Use { "$absent": true } as an object field value to assert that the field is absent from the normalized actual response. A present field, including null, fails.

Semantic matcher objects are opt-in expected values and work in both modes:

  • { "$same_instant": "2026-05-30T10:00:00Z" } — actual and expected values must be RFC3339 strings that represent the same instant.
  • { "$rfc3339": true } — actual value must be an RFC3339 date-time string. Use it when only the format matters and the instant is dynamic.
  • { "$matches": "^trace-\\d+$" } — actual value must be a string that matches the regular expression.
  • { "$not_empty": true } — actual value must be a non-empty string, array, or object. " " passes; "", [], {}, null, numbers, and booleans fail.

For expected errors, use message_contains when the error message is part of the contract.

Run options

itestkit.RunCases(
    t,
    cases,
    lifecycle,
    caseFactory,
    inspector,
    codec,
    itestkit.WithContinueOnFailure(),
    itestkit.WithParallelCases(),
    itestkit.WithParallelismLimit(20),
)

Options:

  • WithContinueOnFailure() — run remaining cases after a failure;
  • WithParallelCases() — run cases in parallel;
  • WithParallelismLimit(n) — run cases in parallel with an explicit limit.

Included helpers

Core helpers:

  • itestkit.NewMapRegistry — registry backed by a map from handler name to handler;
  • itestkit.DecodeStrictJSON — JSON decoder that rejects unknown fields and trailing data;
  • itestkit.DecodeExpectedJSON — JSON decoder for marker-aware expectations in custom handlers;
  • itestkit.MatchExpectedJSON — compares expected JSON with JSON-safe actual data using MatchModeExact or MatchModePartial.

Additional packages:

  • github.com/n-r-w/itestkit/grpc — gRPC handler helpers and protobuf JSON normalization;
  • github.com/n-r-w/itestkit/grpc/bufconn — in-memory gRPC server/client helpers;
  • github.com/n-r-w/itestkit/httpmock — JSONC-driven outbound HTTP mock server;
  • github.com/n-r-w/itestkit/httpserver — JSONC-driven calls to an in-process net/http.Handler;
  • github.com/n-r-w/itestkit/testcalendar — deterministic date and timestamp macros for JSONC cases;
  • github.com/n-r-w/itestkit/queue/kafkaproducer — Kafka producer test harness;
  • github.com/n-r-w/itestkit/queue/itest — ready-made queue step registry.

HTTP server helper

Use httpserver.NewRegistry or httpserver.NewCallHandler when JSONC cases need to call an in-process net/http.Handler. The case harness must expose HTTPHandler() http.Handler.

Preset handler:

  • CallHTTP — builds an HTTP request from JSONC, calls the handler, and normalizes the response.

Request fields:

  • method, path, query, headers, body, raw_body;
  • use_cookies — attaches cookies stored from earlier responses in the same case;
  • csrf.cookie, csrf.header — copies one stored cookie value into one request header and fails if the header is already set manually;
  • capture_headers, capture_cookies — selects response headers and cookies for assertion. Requested absent headers are returned as empty arrays.

Cookie reuse requires per-case state:

type harness struct {
    handler http.Handler
    cookies *httpserver.CookieJar
}

func (h *harness) HTTPHandler() http.Handler { return h.handler }
func (h *harness) HTTPCookieJar() *httpserver.CookieJar { return h.cookies }

See docs/itestkit/examples/httpserver for a complete JSONC example.

HTTP mock helper

Use httpmock.NewServer(t) in a per-case harness when the system under test needs a base URL for outbound HTTP calls. The harness must expose HTTPMock() *httpmock.Server for preset handlers.

Preset handlers:

  • PlanHTTPCalls — stores expected requests and stub responses;
  • AwaitHTTPCalls — checks whether planned requests have been observed;
  • VerifyHTTPCalls — performs the final request verification.

Plan fields:

  • request match: method, path, query, query_mode, headers, headers_mode, headers_present, body, body_subset, raw_body, expected_count;
  • response stub: response.status, response.headers, response.body, response.raw_body;
  • ordering: ordering with values strict and any.

Mode values:

  • query_mode: exact, subset; empty means exact;
  • headers_mode: exact, subset; empty means exact;
  • headers_present checks that headers exist without comparing their values;
  • ordering: strict, any; empty means any.

Body rules:

  • body is exact JSON matching;
  • body_subset is JSON subset matching;
  • raw_body is exact string matching;
  • set only one of body, body_subset, and raw_body per request expectation.

See docs/itestkit/examples/httpmock for a complete JSONC example.

LLM skill

  • docs/itestkit/SKILL.md
  • docs/itestkit/examples/custom — minimal custom integration;
  • docs/itestkit/examples/grpc — gRPC client integration;
  • docs/itestkit/examples/extapigrpcadapter — adapter-style gRPC target and dial options;
  • docs/itestkit/examples/httpserver — inbound HTTP handler flow;
  • docs/itestkit/examples/httpmock — outbound HTTP mock flow;
  • docs/itestkit/examples/queue/inbound — inbound queue flow;
  • docs/itestkit/examples/queue/outbound — outbound Kafka flow;
  • docs/itestkit/examples/bookingcalendar — calendar macros and fixed test time;
  • docs/itestkit/examples/real — project-like layout with service and integration tests.

Documentation

Overview

Package itestkit is a generated GoMock package.

Package itestkit is a portable core for running integration tests on JSONC cases.

Index

Constants

View Source
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

func MatchExpectedJSON(expected, actual any, mode MatchMode) error

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

type AwaitRetry struct {
	TimeoutMS   int
	IntervalMS  int
	MaxAttempts int
}

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.

const (
	// MatchModeExact requires expected and actual JSON structures to match completely.
	MatchModeExact MatchMode = "exact"
	// MatchModePartial requires expected object fields to match as a subset of actual objects.
	MatchModePartial MatchMode = "partial"
)

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

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCaseSource) ReadDir

func (m *MockCaseSource) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir mocks base method.

func (*MockCaseSource) ReadFile

func (m *MockCaseSource) ReadFile(name string) ([]byte, error)

ReadFile mocks base method.

type MockCaseSourceMockRecorder

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

MockCaseSourceMockRecorder is the mock recorder for MockCaseSource.

func (*MockCaseSourceMockRecorder) ReadDir

func (mr *MockCaseSourceMockRecorder) ReadDir(name any) *gomock.Call

ReadDir indicates an expected call of ReadDir.

func (*MockCaseSourceMockRecorder) ReadFile

func (mr *MockCaseSourceMockRecorder) ReadFile(name any) *gomock.Call

ReadFile indicates an expected call of ReadFile.

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

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockErrorInspector[S]) FromError

func (m *MockErrorInspector[S]) FromError(err error) (S, string, bool)

FromError mocks base method.

type MockErrorInspectorMockRecorder

type MockErrorInspectorMockRecorder[S comparable] struct {
	// contains filtered or unexported fields
}

MockErrorInspectorMockRecorder is the mock recorder for MockErrorInspector.

func (*MockErrorInspectorMockRecorder[S]) FromError

func (mr *MockErrorInspectorMockRecorder[S]) FromError(err any) *gomock.Call

FromError indicates an expected call of FromError.

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]) Invoke

func (m *MockHandler[C]) Invoke(ctx context.Context, client C, request any) (any, error)

Invoke mocks base method.

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

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

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.

func (*MockHarnessFactoryMockRecorder[C]) New

New indicates an expected call of New.

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

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

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.

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.

Jump to

Keyboard shortcuts

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