assertions

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package assertions provides event assertion utilities for testing event-sourced systems. It includes helpers for comparing events, checking event types, and generating event diffs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAllMatch

func AssertAllMatch(t TB, events []interface{}, matcher EventMatcher)

AssertAllMatch checks that all events match the matcher.

func AssertAnyMatch

func AssertAnyMatch(t TB, events []interface{}, matcher EventMatcher)

AssertAnyMatch checks that at least one event matches the matcher.

func AssertContainsEvent

func AssertContainsEvent[T any](t TB, events []interface{}, expected T)

AssertContainsEvent checks that the events contain an event of the expected type and data.

func AssertContainsEventType

func AssertContainsEventType(t TB, events []interface{}, typeName string)

AssertContainsEventType checks that the events contain at least one event of the specified type.

func AssertEventAtIndex

func AssertEventAtIndex[T any](t TB, events []interface{}, index int, expected T)

AssertEventAtIndex checks the event at a specific index matches the expected data.

func AssertEventCount

func AssertEventCount(t TB, events []interface{}, expected int)

AssertEventCount checks the number of events.

func AssertEventData

func AssertEventData[T any](t TB, event interface{}, expected T)

AssertEventData checks that a specific event matches the expected data.

func AssertEventTypes

func AssertEventTypes(t TB, events []interface{}, types ...string)

AssertEventTypes checks that the events have the expected types in order.

func AssertEventsEqual

func AssertEventsEqual(t TB, expected, actual []interface{})

AssertEventsEqual compares two event slices and fails if they differ.

func AssertEventsMatch

func AssertEventsMatch(t TB, expected, actual []interface{})

AssertEventsMatch checks that actual events match expected events, allowing for extra events at the end.

func AssertFirstEvent

func AssertFirstEvent[T any](t TB, events []interface{}, expected T)

AssertFirstEvent checks the first event matches the expected data.

func AssertLastEvent

func AssertLastEvent[T any](t TB, events []interface{}, expected T)

AssertLastEvent checks the last event matches the expected data.

func AssertNoEvents

func AssertNoEvents(t TB, events []interface{})

AssertNoEvents checks that no events were produced.

func AssertNoneMatch

func AssertNoneMatch(t TB, events []interface{}, matcher EventMatcher)

AssertNoneMatch checks that no events match the matcher.

func CountMatches

func CountMatches(events []interface{}, matcher EventMatcher) int

CountMatches returns the number of events that match the matcher.

func FilterEvents

func FilterEvents(events []interface{}, matcher EventMatcher) []interface{}

FilterEvents returns events that match the matcher.

func FormatDiffs

func FormatDiffs(diffs []EventDiff) string

FormatDiffs formats event diffs as a human-readable string.

Types

type DiffType

type DiffType int

DiffType represents the type of difference.

const (
	// DiffMissing indicates an expected event was not present.
	DiffMissing DiffType = iota
	// DiffExtra indicates an unexpected event was present.
	DiffExtra
	// DiffMismatch indicates event data did not match.
	DiffMismatch
)

func (DiffType) String

func (d DiffType) String() string

String returns a human-readable representation of the diff type.

type EventDiff

type EventDiff struct {
	Index    int
	Expected interface{}
	Actual   interface{}
	Type     DiffType
}

EventDiff represents a difference between expected and actual events.

func DiffEvents

func DiffEvents(expected, actual []interface{}) []EventDiff

DiffEvents compares two event slices and returns the differences.

type EventMatcher

type EventMatcher func(event interface{}) bool

EventMatcher is a function that checks if an event matches certain criteria.

func MatchEvent

func MatchEvent[T any](expected T) EventMatcher

MatchEvent returns a matcher that checks for exact event equality.

func MatchEventType

func MatchEventType(typeName string) EventMatcher

MatchEventType returns a matcher that checks for a specific event type.

type TB

type TB = testing.TB

TB is an alias for testing.TB interface to allow mocking in tests

Jump to

Keyboard shortcuts

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