journal

package
v0.233.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package journal records Management API calls in a bounded in-memory ring so tests can assert on what the application under test actually sent.

Index

Constants

View Source
const MaxStoredBody = 64 << 10

MaxStoredBody is the most request-body bytes kept per entry.

Variables

This section is empty.

Functions

func MarkMatched

func MarkMatched(ctx context.Context, expectationID string)

MarkMatched records that a stub served the call. ExpectationID is empty for the SSE stream. It is a no-op when ctx has no journal slot.

func MarkNoMatch

func MarkNoMatch(ctx context.Context, nearMisses []matches.NearMiss)

MarkNoMatch records that no stub matched, with the closest candidates. It is a no-op when ctx has no journal slot.

Types

type Entry

type Entry struct {
	ID            string             `json:"id"`
	ReceivedAt    time.Time          `json:"receivedAt"`
	Method        string             `json:"method"`
	Path          string             `json:"path"`
	Operation     string             `json:"operation"`
	Query         url.Values         `json:"query"`
	Headers       http.Header        `json:"headers"`
	Body          json.RawMessage    `json:"body,omitempty"`
	BodyTruncated bool               `json:"bodyTruncated,omitempty"`
	Status        int                `json:"status"`
	Outcome       Outcome            `json:"outcome"`
	ExpectationID string             `json:"expectationId,omitempty"`
	NearMisses    []matches.NearMiss `json:"nearMisses,omitempty"`
}

Entry is one recorded Management API call.

type Filter

type Filter struct{ Method, Path string }

Filter narrows List and Unmatched. Empty fields match everything. A Path containing "{...}" is compared with the entry's Operation, otherwise with its concrete Path.

type Journal

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

Journal is a fixed-size ring of entries, safe for concurrent use.

func New

func New(size int) *Journal

New returns a journal keeping the newest size entries. A size <= 0 disables recording.

func (*Journal) Clear

func (j *Journal) Clear()

Clear drops every entry.

func (*Journal) List

func (j *Journal) List(f Filter) []Entry

List returns matching entries, oldest first. It never returns nil.

func (*Journal) Middleware

func (j *Journal) Middleware(next http.Handler) http.Handler

Middleware records every /api/v2/ call once its response starts.

func (*Journal) Unmatched

func (j *Journal) Unmatched(f Filter) []Entry

Unmatched returns matching entries whose outcome is no_match.

type Outcome

type Outcome string

Outcome says how the mock resolved a recorded call.

const (
	// OutcomeMatched means a stub (or the SSE stream) served the call.
	OutcomeMatched Outcome = "matched"
	// OutcomeNoMatch means the call was well formed but no stub matched.
	OutcomeNoMatch Outcome = "no_match"
	// OutcomeRejected means the call never reached stub matching (auth,
	// validation, unknown route, ...).
	OutcomeRejected Outcome = "rejected"
)

Jump to

Keyboard shortcuts

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