stdcrpcsnap

package
v0.0.190 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package stdcrpcsnap provides snapshot testing for Connect RPC response.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOverwrite added in v0.0.111

func ApplyOverwrite(tb require.TestingT, actMsg []byte, actOverwrites ...Overwrite) []byte

ApplyOverwrite returns a version of the message where the overwrites are applied and assertions checked.

func MessageSnapshotEq

func MessageSnapshotEq(tb testing.TB, msg proto.Message, actOverwrites ...Overwrite)

MessageSnapshotEq compares the protobuf message against a snapshot. If the snapshot file doesn't exist it is created instead.

func ResponseSnapshotEq

func ResponseSnapshotEq[O any](
	tb testing.TB, resp *connect.Response[O], err error, actOverwrites ...Overwrite,
)

ResponseSnapshotEq asserts that the snapshot equals the RPC response.

func SnapshotEq

func SnapshotEq(tb testing.TB, actMsg []byte, actOverwrites ...Overwrite)

SnapshotEq compares the protobuf message against a snapshot. If the snapshot file doesn't exist it is created instead. It allows overwriting parts of the message with static values while asserting the replaced values precicely. This allows for part of the message to be dynanmic but still tightly asserted.

Types

type Overwrite

type Overwrite struct {
	Path   string
	Value  any
	Assert OverwriteAssertFunc
}

Overwrite allows a test case to overwrite part of the actual message before it is compared with the snapshot. This is useful for asserting data that changes by definition. It is a last-resort option and making sure the data is stable to begin with is preferred.

func PinResponseValue

func PinResponseValue(atPath string, toValue any, assertActual ...OverwriteAssertFunc) Overwrite

PinResponseValue is a helper that allows for dealing with response values that are not static so cannot be predicted for the snapshot value. The optional 'assertActual' can still assert the actual value even though it wouldn't match the snapshot.

type OverwriteAssertFunc added in v0.0.104

type OverwriteAssertFunc func(t assert.TestingT, v gjson.Result)

OverwriteAssertFunc allows asserting overwitten values.

func AssertRFC3339Nano added in v0.0.110

func AssertRFC3339Nano() OverwriteAssertFunc

AssertRFC3339Nano is a re-usable check to assert overwritten values.

func AssertStringOfLength added in v0.0.110

func AssertStringOfLength(n int) OverwriteAssertFunc

AssertStringOfLength is a re-usable check to assert just length values.

func AssertUUID added in v0.0.110

func AssertUUID() OverwriteAssertFunc

AssertUUID is a re-usable check to assert overwritten values.

Jump to

Keyboard shortcuts

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