Documentation
¶
Overview ¶
Package testutil holds the small assertion helpers shared by tests, so they stay on the stdlib testing package. Plain functions (Equal, NoError, ...) mark the test failed and continue; the Require-prefixed forms stop it.
Index ¶
- func Contains(t testing.TB, container, elem any, msg ...any)
- func Empty(t testing.TB, v any, msg ...any)
- func Equal(t testing.TB, want, got any, msg ...any)
- func EqualError(t testing.TB, err error, want string, msg ...any)
- func Error(t testing.TB, err error, msg ...any)
- func ErrorIs(t testing.TB, err, target error, msg ...any)
- func False(t testing.TB, v bool, msg ...any)
- func JSONEqual(t testing.TB, want, got string, msg ...any)
- func Len(t testing.TB, v any, want int, msg ...any)
- func LessOrEqual[T int | int64 | float64 | string](t testing.TB, a, b T, msg ...any)
- func Nil(t testing.TB, v any, msg ...any)
- func NoError(t testing.TB, err error, msg ...any)
- func NotContains(t testing.TB, container, elem any, msg ...any)
- func NotEmpty(t testing.TB, v any, msg ...any)
- func NotEqual(t testing.TB, a, b any, msg ...any)
- func NotErrorIs(t testing.TB, err, target error, msg ...any)
- func NotNil(t testing.TB, v any, msg ...any)
- func RequireEqual(t testing.TB, want, got any, msg ...any)
- func RequireError(t testing.TB, err error, msg ...any)
- func RequireErrorIs(t testing.TB, err, target error, msg ...any)
- func RequireJSONEqual(t testing.TB, want, got string, msg ...any)
- func RequireLen(t testing.TB, v any, want int, msg ...any)
- func RequireNoError(t testing.TB, err error, msg ...any)
- func RequireNotNil(t testing.TB, v any, msg ...any)
- func True(t testing.TB, v bool, msg ...any)
- type QueryCounter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualError ¶
EqualError fails the test unless err is non-nil with exactly the given message.
func JSONEqual ¶
JSONEqual fails the test unless both strings are JSON documents with equal content.
func LessOrEqual ¶
LessOrEqual fails the test unless a <= b.
func NotContains ¶
NotContains fails the test when the string, slice, array or map holds elem.
func NotErrorIs ¶
NotErrorIs fails the test when err wraps target.
func RequireEqual ¶
RequireEqual is Equal, stopping the test on failure.
func RequireError ¶
RequireError is Error, stopping the test on failure.
func RequireErrorIs ¶
RequireErrorIs is ErrorIs, stopping the test on failure.
func RequireJSONEqual ¶
RequireJSONEqual is JSONEqual, stopping the test on failure.
func RequireLen ¶
RequireLen is Len, stopping the test on failure.
func RequireNoError ¶
RequireNoError is NoError, stopping the test on failure.
func RequireNotNil ¶
RequireNotNil is NotNil, stopping the test on failure.
Types ¶
type QueryCounter ¶
type QueryCounter struct {
// contains filtered or unexported fields
}
QueryCounter is a pgx.QueryTracer that records the statements a pool runs. Set it as ConnConfig.Tracer before the pool is created, then compare Count before and after the code under test (Since lists what ran in between).
func (*QueryCounter) Count ¶
func (c *QueryCounter) Count() int
Count is the number of statements started so far.
func (*QueryCounter) Since ¶
func (c *QueryCounter) Since(n int) []string
Since returns the statements started after the first n (n from Count).
func (*QueryCounter) TraceQueryEnd ¶
func (c *QueryCounter) TraceQueryEnd(context.Context, *pgx.Conn, pgx.TraceQueryEndData)
TraceQueryEnd is part of pgx.QueryTracer.
func (*QueryCounter) TraceQueryStart ¶
func (c *QueryCounter) TraceQueryStart(ctx context.Context, _ *pgx.Conn, d pgx.TraceQueryStartData) context.Context
TraceQueryStart records one statement.