Documentation
¶
Index ¶
- func AccessKey(t *testing.T, key *ecdsa.PrivateKey, claims elephantine.JWTClaims) string
- func AgainstGolden[T any](t *testing.T, regenerate bool, got T, goldenPath string, ...)
- func Claims(t *testing.T, user string, scope string, units ...string) elephantine.JWTClaims
- func CloneMessage[T proto.Message](msg T) T
- func CommonTimeFields() []string
- func Context(c Cleaner) context.Contextdeprecated
- func Equal[T comparable](t TestingT, want T, got T, format string, a ...any)deprecated
- func EqualDiff[T any](t TestingT, want T, got T, format string, a ...any)
- func EqualDiffWithOptions[T any](t TestingT, want T, got T, opts cmp.Options, format string, a ...any)deprecated
- func EqualDiffWithOptionsf[T any](t TestingT, want T, got T, opts cmp.Options, format string, a ...any)
- func EqualMessage(t TestingT, want proto.Message, got proto.Message, format string, a ...any)deprecated
- func EqualMessageWithOptions(t TestingT, want proto.Message, got proto.Message, opts cmp.Options, ...)deprecated
- func EqualMessageWithOptionsf(t TestingT, want proto.Message, got proto.Message, opts cmp.Options, ...)
- func EqualMessagef(t TestingT, want proto.Message, got proto.Message, format string, a ...any)
- func Equalf[T comparable](t TestingT, want T, got T, format string, a ...any)
- func ErrorParity(t TestingT, twirpErr error, connectErr error)
- func IsRPCError(t TestingT, err error, code connect.Code)
- func IsTwirpError(t TestingT, err error, code twirp.ErrorCode)deprecated
- func MessageAgainstGolden(t *testing.T, regenerate bool, got proto.Message, goldenPath string, ...)
- func MessagesAgainstGolden[T proto.Message](t *testing.T, regenerate bool, gotSlice []T, goldenPath string, ...)
- func Must(t TestingT, err error, format string, a ...any)deprecated
- func MustNot(t TestingT, err error, format string, a ...any)deprecated
- func MustNotf(t TestingT, err error, format string, a ...any)
- func Mustf(t TestingT, err error, format string, a ...any)
- func NewLogHandler(t TestingLogger, level slog.Level) slog.Handler
- func NewSigningKey(t *testing.T) *ecdsa.PrivateKey
- func NotNil[T any](t TestingT, v *T, format string, a ...any)deprecated
- func NotNilf[T any](t TestingT, v *T, format string, a ...any)
- func Regenerate() bool
- func StandardClaims(t *testing.T, scope string, units ...string) elephantine.JWTClaims
- func TestAgainstGolden[T any](t *testing.T, regenerate bool, got T, goldenPath string, ...)deprecated
- func TestMessageAgainstGolden(t *testing.T, regenerate bool, got proto.Message, goldenPath string, ...)deprecated
- func TestMessagesAgainstGolden[T proto.Message](t *testing.T, regenerate bool, gotSlice []T, goldenPath string, ...)deprecated
- type Cleaner
- type GoldenHelper
- type GoldenHelperForAny
- type IgnoreField
- type IgnoreTimestamps
- type LogHandler
- func (h *LogHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *LogHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *LogHandler) WithGroup(name string) slog.Handler
- func (h *LogHandler) Write(data []byte) (int, error)
- type Loggerdeprecated
- type TestingLogger
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessKey ¶ added in v0.20.3
func AccessKey( t *testing.T, key *ecdsa.PrivateKey, claims elephantine.JWTClaims, ) string
AccessKey creates a signed access key from the signing key and claims.
func AgainstGolden ¶ added in v0.27.2
func AgainstGolden[T any]( t *testing.T, regenerate bool, got T, goldenPath string, helpers ...GoldenHelper, )
AgainstGolden compares a result against the contents of the file at the goldenPath. Run with regenerate set to true to create or update the file.
func CloneMessage ¶
CloneMessage allows for type safe cloning of protobuf messages.
func CommonTimeFields ¶ added in v0.17.10
func CommonTimeFields() []string
func EqualDiff ¶ added in v0.3.0
EqualDiff runs a cmp.Diff to do a deep equal check with readable diff output.
func EqualDiffWithOptions
deprecated
added in
v0.21.1
func EqualDiffWithOptions[T any]( t TestingT, want T, got T, opts cmp.Options, format string, a ...any, )
EqualDiffWithOptions is a shim for EqualDiffWithOptionsf.
Deprecated: use EqualDiffWithOptionsf instead.
func EqualDiffWithOptionsf ¶ added in v0.27.2
func EqualMessage
deprecated
EqualMessage is a shim for EqualMessagef.
Deprecated: use EqualMessagef instead.
func EqualMessageWithOptions
deprecated
added in
v0.17.2
func EqualMessageWithOptionsf ¶ added in v0.27.2
func EqualMessageWithOptionsf(t TestingT, want proto.Message, got proto.Message, opts cmp.Options, format string, a ...any, )
EqualMessageWithOptionsf runs a cmp.Diff with protobuf-specific options plus the additional cmp.Options provided by the caller.
func EqualMessagef ¶ added in v0.27.2
EqualMessagef runs a cmp.Diff with protobuf-specific options.
func Equalf ¶ added in v0.27.2
func Equalf[T comparable](t TestingT, want T, got T, format string, a ...any)
func ErrorParity ¶ added in v0.29.0
ErrorParity checks that a Twirp error and a Connect error describe the same failure: the same code, the same message and the same error metadata. It is what makes a service's move to the Connect error vocabulary checkable, by running the same call against both stacks and comparing the two errors.
func IsRPCError ¶ added in v0.29.0
IsRPCError checks that the error is an RPC error with the given code. Both *connect.Error and twirp.Error are accepted, so a test does not have to be changed at the same time as the client constructor that produces its errors.
func IsTwirpError
deprecated
IsTwirpError checks that the error is a Twirp error with the given code.
Deprecated: use IsRPCError, which takes a connect.Code and accepts both error types, so the check does not have to change with the client constructor.
func MessageAgainstGolden ¶ added in v0.27.2
func MessageAgainstGolden( t *testing.T, regenerate bool, got proto.Message, goldenPath string, helpers ...GoldenHelper, )
MessageAgainstGolden compares a protobuf message against the contents of the file at the goldenPath. Run with regenerate set to true to create or update the file.
func MessagesAgainstGolden ¶ added in v0.27.2
func MessagesAgainstGolden[T proto.Message]( t *testing.T, regenerate bool, gotSlice []T, goldenPath string, helpers ...GoldenHelper, )
MessagesAgainstGolden compares a slice of protobuf messages against the contents of the file at the goldenPath. Run with regenerate set to true to create or update the file.
func NewLogHandler ¶
func NewLogHandler(t TestingLogger, level slog.Level) slog.Handler
NewLogHandler returns a slog.Handler that logs through t. Once t's cleanup has run the handler silently drops further records: the cleanup and the write into t.Log are serialised, so a record either reaches t.Log before the cleanup returns, while logging is still legal, or is dropped.
func NewSigningKey ¶ added in v0.20.3
func NewSigningKey(t *testing.T) *ecdsa.PrivateKey
NewSigningKey creates a signing key for use with a elephantine.NewStaticAuthInfoParser.
func Regenerate ¶ added in v0.23.5
func Regenerate() bool
Regenerate returns true if the environment variable REGENERATE is set to "true", signalling that golden test fixtures should be regenerated.
func StandardClaims ¶ added in v0.20.3
StandardClaims is a helper function that creates standard claims for a test.
func TestAgainstGolden
deprecated
added in
v0.21.1
func TestAgainstGolden[T any]( t *testing.T, regenerate bool, got T, goldenPath string, helpers ...GoldenHelper, )
TestAgainstGolden compares a result against the contents of the file at the goldenPath. Run with regenerate set to true to create or update the file.
Deprecated: use AgainstGolden instead.
func TestMessageAgainstGolden
deprecated
added in
v0.17.2
func TestMessageAgainstGolden( t *testing.T, regenerate bool, got proto.Message, goldenPath string, helpers ...GoldenHelper, )
TestMessageAgainstGolden compares a protobuf message against the contents of the file at the goldenPath. Run with regenerate set to true to create or update the file.
Deprecated: use MessageAgainstGolden instead.
func TestMessagesAgainstGolden
deprecated
added in
v0.22.1
func TestMessagesAgainstGolden[T proto.Message]( t *testing.T, regenerate bool, gotSlice []T, goldenPath string, helpers ...GoldenHelper, )
TestMessagesAgainstGolden compares a slice of protobuf messages against the contents of the file at the goldenPath. Run with regenerate set to true to create or update the file.
Deprecated: use MessagesAgainstGolden instead.
Types ¶
type Cleaner ¶
type Cleaner interface {
Cleanup(fn func())
}
Cleaner is the subset of testing.TB used to register cleanup callbacks, satisfied by *testing.T.
type GoldenHelper ¶ added in v0.17.10
GoldenHelper customises golden-file comparisons: CmpOpts contributes cmp.Options used when diffing, and JSONTransform rewrites the decoded JSON before it is stored, typically to mask volatile fields. See IgnoreField and IgnoreTimestamps.
type GoldenHelperForAny ¶ added in v0.21.1
GoldenHelperForAny is an optional extension of GoldenHelper for helpers that can also transform non-object JSON values, such as a top-level array.
type IgnoreField ¶ added in v0.20.1
IgnoreField is a GoldenHelper that ignores a named field during comparison and replaces its value with DummyValue when storing the golden file. An optional Validator can assert something about the original value before it is masked.
func (IgnoreField[T]) CmpOpts ¶ added in v0.20.1
func (fi IgnoreField[T]) CmpOpts() cmp.Options
CmpOpts implements GoldenHelper.
func (IgnoreField[T]) JSONTransform ¶ added in v0.20.1
func (fi IgnoreField[T]) JSONTransform(value map[string]any) error
JSONTransform implements GoldenHelper.
type IgnoreTimestamps ¶ added in v0.17.10
IgnoreTimestamps is a GoldenHelper that masks timestamp fields during comparison and replaces them with a fixed value when storing the golden file. When Fields is empty CommonTimeFields is used, and Format defaults to time.RFC3339.
func (IgnoreTimestamps) CmpOpts ¶ added in v0.17.10
func (it IgnoreTimestamps) CmpOpts() cmp.Options
func (IgnoreTimestamps) JSONTransform ¶ added in v0.17.10
func (it IgnoreTimestamps) JSONTransform(value map[string]any) error
type LogHandler ¶
type LogHandler struct {
// contains filtered or unexported fields
}
LogHandler is a slog.Handler that writes log records through a TestingLogger's Log method, so log output is attributed to the running test. Once the test's cleanup has run it silently drops further records. Create it with NewLogHandler.
Every record, including those from handlers derived with WithAttrs and WithGroup, is written through Write, which is where the guard lives.
type Logger
deprecated
type Logger = TestingLogger
Logger is the previous interface for NewLogHandler. Use TestingLogger instead.
Deprecated: use TestingLogger.
type TestingLogger ¶ added in v0.24.0
type TestingLogger interface {
Log(args ...any)
Cleanup(fn func())
}
TestingLogger is satisfied by *testing.T and *testing.B.