test

package
v0.23.7 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

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 Claims added in v0.20.3

func Claims(
	t *testing.T, user string, scope string, units ...string,
) elephantine.JWTClaims

Claims creates an elephantine.JWTClaims struct for use in thesting.

func CloneMessage

func CloneMessage[T proto.Message](msg T) T

CloneMessage allows for type safe cloning of protobuf messages.

func CommonTimeFields added in v0.17.10

func CommonTimeFields() []string

func Context deprecated

func Context(c Cleaner) context.Context

Deprecated: Use testing.T.Context() instead.

func Equal

func Equal[T comparable](t TestingT, want T, got T, format string, a ...any)

func EqualDiff added in v0.3.0

func EqualDiff[T any](t TestingT,
	want T, got T,
	format string, a ...any,
)

EqualDiff runs a cmp.Diff to do a deep equal check with readable diff output.

func EqualDiffWithOptions added in v0.21.1

func EqualDiffWithOptions[T any](
	t TestingT,
	want T, got T,
	opts cmp.Options,
	format string, a ...any,
)

EqualMessage runs a cmp.Diff with protobuf-specific options.

func EqualMessage

func EqualMessage(t TestingT,
	want proto.Message, got proto.Message,
	format string, a ...any,
)

EqualMessage runs a cmp.Diff with protobuf-specific options.

func EqualMessageWithOptions added in v0.17.2

func EqualMessageWithOptions(t TestingT,
	want proto.Message, got proto.Message,
	opts cmp.Options,
	format string, a ...any,
)

EqualMessage runs a cmp.Diff with protobuf-specific options.

func IsTwirpError

func IsTwirpError(
	t TestingT, err error, code twirp.ErrorCode,
)

func Must

func Must(t TestingT, err error, format string, a ...any)

func MustNot

func MustNot(t TestingT, err error, format string, a ...any)

func NewLogHandler

func NewLogHandler(t Logger, level slog.Level) slog.Handler

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 NotNil

func NotNil[T any](t TestingT, v *T, format string, a ...any)

func Regenerate added in v0.23.5

func Regenerate() bool

Regenerate test fixtures will return true if the environment variable REGENERATE is set to true.

func StandardClaims added in v0.20.3

func StandardClaims(
	t *testing.T, scope string, units ...string,
) elephantine.JWTClaims

StandardClaims is a helper function that creates standard claims for a test.

func TestAgainstGolden 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.

func TestMessageAgainstGolden 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.

func TestMessagesAgainstGolden 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.

Types

type Cleaner

type Cleaner interface {
	Cleanup(fn func())
}

type GoldenHelper added in v0.17.10

type GoldenHelper interface {
	CmpOpts() cmp.Options
	JSONTransform(value map[string]any) error
}

type GoldenHelperForAny added in v0.21.1

type GoldenHelperForAny interface {
	JSONTransformAny(value any) error
}

type IgnoreField added in v0.20.1

type IgnoreField[T any] struct {
	Name       string
	DummyValue T
	Validator  func(v T) error
}

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

type IgnoreTimestamps struct {
	Fields     []string
	DummyValue time.Time
	Format     string
}

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
}

func (*LogHandler) Enabled

func (h *LogHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*LogHandler) Handle

func (h *LogHandler) Handle(ctx context.Context, r slog.Record) error

func (*LogHandler) WithAttrs

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*LogHandler) WithGroup

func (h *LogHandler) WithGroup(name string) slog.Handler

func (*LogHandler) Write

func (h *LogHandler) Write(data []byte) (int, error)

type Logger

type Logger interface {
	Log(args ...any)
}

type TestingT

type TestingT interface {
	Helper()
	Fatalf(format string, args ...any)
	Logf(format string, args ...any)
}

Jump to

Keyboard shortcuts

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