Documentation
¶
Overview ¶
Package stdcrpcsnap provides snapshot testing for Connect RPC response.
Index ¶
- func ApplyOverwrite(tb require.TestingT, actMsg []byte, actOverwrites ...Overwrite) []byte
- func MessageSnapshotEq(tb testing.TB, msg proto.Message, actOverwrites ...Overwrite)
- func ResponseSnapshotEq[O any](tb testing.TB, resp *connect.Response[O], err error, ...)
- func SnapshotEq(tb testing.TB, actMsg []byte, actOverwrites ...Overwrite)
- type Overwrite
- type OverwriteAssertFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyOverwrite ¶ added in v0.0.111
ApplyOverwrite returns a version of the message where the overwrites are applied and assertions checked.
func MessageSnapshotEq ¶
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 ¶
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
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.