stdcrpcsnap

package
v0.0.107 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 12 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 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.

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(tb testing.TB, v gjson.Result)

OverwriteAssertFunc allows asserting overwitten values.

Jump to

Keyboard shortcuts

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