tests

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Fatal is an option that means if the test fails, the test will be stopped.
	Fatal = &opt{
		fn: func(context *validator) *validator {
			context.Fatal()
			return context
		},
	}
)

Functions

This section is empty.

Types

type Context1 added in v0.2.0

type Context1[A any] struct {
	// contains filtered or unexported fields
}

Context1 is a test context that allows for easy testing of values. This context contains only a single value and provides methods to test equality and differences.

func Execute added in v0.2.0

func Execute[A any](one A) *Context1[A]

Execute creates a new context with the given value. Ideally, you'd just call the function you are testing directly: tests.Execute(struct.function()). This allows you to use the context methods to test the result: tests.Execute(struct.function()).Equal(t, expected).

func (*Context1[A]) Capture added in v0.2.0

func (ctx *Context1[A]) Capture() A

Capture returns the value.

func (*Context1[A]) Diff added in v0.2.0

func (ctx *Context1[A]) Diff(t testing.TB, other A, opts ...Opt)

Diff checks that the value is different from the given value.

func (*Context1[A]) Equal added in v0.2.0

func (ctx *Context1[A]) Equal(t testing.TB, other A, opts ...Opt)

Equal checks that the value is equal to the given value.

func (*Context1[A]) NotEqual added in v0.2.0

func (ctx *Context1[A]) NotEqual(t testing.TB, other A, opts ...Opt)

NotEqual checks that the value is not equal to the given value.

func (*Context1[A]) Validate added in v0.2.0

func (ctx *Context1[A]) Validate(t testing.TB, cb func(testing.TB, A))

Validate runs the given callback with the value.

type Context1E added in v0.2.0

type Context1E struct {
	// contains filtered or unexported fields
}

Context1E is a test context that allows for easy testing of errors. This context contains only a single error and provides methods to test for errors.

func ExecuteE added in v0.2.0

func ExecuteE(err error) *Context1E

ExecuteE creates a new context with the given error. Ideally, you'd just call the function you are testing directly: tests.ExecuteE(struct.function()). This allows you to use the context methods to test the result: tests.ExecuteE(struct.function()).NoError(t).

func (*Context1E) Capture added in v0.2.0

func (ctx *Context1E) Capture() error

Capture returns the value.

func (*Context1E) Error added in v0.2.0

func (ctx *Context1E) Error(t testing.TB, opts ...Opt)

Error checks that the value is an error.

func (*Context1E) ErrorCode added in v0.2.2

func (ctx *Context1E) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt)

ErrorCode checks that the value is an error and has the expected error code.

func (*Context1E) MatchesError added in v0.2.0

func (ctx *Context1E) MatchesError(t testing.TB, expected string, opts ...Opt)

MatchesError checks that the value is an error and matches the expected error.

func (*Context1E) NoError added in v0.2.0

func (ctx *Context1E) NoError(t testing.TB, opts ...Opt)

NoError checks that the value is not an error.

func (*Context1E) Validate added in v0.2.0

func (ctx *Context1E) Validate(t testing.TB, cb func(error))

Validate runs the given callback with the value.

type Context2 added in v0.2.0

type Context2[A, B any] struct {
	// contains filtered or unexported fields
}

Context2 is a test context that allows for easy testing of two values. This context contains two values and provides methods to test equality and differences.

func Execute2 added in v0.2.0

func Execute2[A, B any](one A, two B) *Context2[A, B]

Execute2 creates a new context with two values. Ideally, you'd just call the function you are testing directly: tests.Execute2(struct.function()). This allows you to use the context methods to test the result: tests.Execute2(struct.function()).Equal(t, expected).Equal(t, otherExpected).

This context contains two values and provides methods to test equality and differences.

Every method returns a new context with the same first value, allowing validates to be chained together.

func (*Context2[A, B]) Capture added in v0.2.0

func (ctx *Context2[A, B]) Capture() (B, *Context1[A])

Capture returns the value.

func (*Context2[A, B]) Diff added in v0.2.0

func (ctx *Context2[A, B]) Diff(t testing.TB, other B, opts ...Opt) *Context1[A]

Diff checks that the value is different from the given value.

func (*Context2[A, B]) Equal added in v0.2.0

func (ctx *Context2[A, B]) Equal(t testing.TB, other B, opts ...Opt) *Context1[A]

Equal checks that the value is equal to the given value.

func (*Context2[A, B]) NotEqual added in v0.2.0

func (ctx *Context2[A, B]) NotEqual(t testing.TB, other B, opts ...Opt) *Context1[A]

NotEqual checks that the value is not equal to the given value.

func (*Context2[A, B]) Validate added in v0.2.0

func (ctx *Context2[A, B]) Validate(t testing.TB, cb func(B)) *Context1[A]

Validate runs the given callback with the value.

type Context2E added in v0.2.0

type Context2E[A any] struct {
	// contains filtered or unexported fields
}

Context2E is a test context that allows for easy testing of a value and an error. This context contains a value and an error and provides methods to test equality and differences.

func Execute2E added in v0.2.0

func Execute2E[A any](a A, err error) *Context2E[A]

Execute2E is a helper function that returns a new context with a value and an error. Ideally, you'd just call the function you are testing directly: tests.Execute2E(struct.function()). This allows you to use the context methods to test the result: tests.Execute2E(struct.function()).NoError(t).Equal(t, expected).

func (*Context2E[A]) Capture added in v0.2.2

func (ctx *Context2E[A]) Capture() (error, *Context1[A])

Capture returns the value.

func (*Context2E[A]) Error added in v0.2.0

func (ctx *Context2E[A]) Error(t testing.TB, opts ...Opt) *Context1[A]

Error checks that the value is an error.

func (*Context2E[A]) ErrorCode added in v0.2.2

func (ctx *Context2E[A]) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt) *Context1[A]

ErrorCode checks that the value is an error and has the expected error code.

func (*Context2E[A]) MatchesError added in v0.2.0

func (ctx *Context2E[A]) MatchesError(t testing.TB, expected string, opts ...Opt) *Context1[A]

MatchesError checks that the value is an error and matches the expected error.

func (*Context2E[A]) NoError added in v0.2.0

func (ctx *Context2E[A]) NoError(t testing.TB, opts ...Opt) *Context1[A]

NoError checks that the value is not an error.

func (*Context2E[A]) Validate added in v0.2.0

func (ctx *Context2E[A]) Validate(t testing.TB, cb func(error)) *Context1[A]

Validate runs the given callback with the value.

type Context3 added in v0.2.1

type Context3[A, B, C any] struct {
	// contains filtered or unexported fields
}

Context3 is a test context that allows for easy testing of three values. This context contains three values and provides methods to test equality and differences.

func Execute3 added in v0.2.1

func Execute3[A, B, C any](one A, two B, three C) *Context3[A, B, C]

Execute3 creates a new context with the given values. Ideally, you'd just call the function you are testing directly: tests.Execute3(struct.function()). This allows you to use the context methods to test the result: tests.Execute3(struct.function()).Equal(t, expected).Equal(t, otherExpected).Equal(t, anotherExpected).

This context contains three values and provides methods to test equality and differences.

Every method returns a new context with the same first two values, allowing validates to be chained together.

func (*Context3[A, B, C]) Capture added in v0.2.1

func (ctx *Context3[A, B, C]) Capture() (C, *Context2[A, B])

Capture returns the value.

func (*Context3[A, B, C]) Diff added in v0.2.1

func (ctx *Context3[A, B, C]) Diff(t testing.TB, other C, opts ...Opt) *Context2[A, B]

Diff checks that the value is different from the given value.

func (*Context3[A, B, C]) Equal added in v0.2.1

func (ctx *Context3[A, B, C]) Equal(t testing.TB, other C, opts ...Opt) *Context2[A, B]

Equal checks that the value is equal to the given value.

func (*Context3[A, B, C]) NotEqual added in v0.2.1

func (ctx *Context3[A, B, C]) NotEqual(t testing.TB, other C, opts ...Opt) *Context2[A, B]

NotEqual checks that the value is not equal to the given value.

func (*Context3[A, B, C]) Validate added in v0.2.1

func (ctx *Context3[A, B, C]) Validate(t testing.TB, cb func(C)) *Context2[A, B]

Validate runs the given callback with the value.

type Context3E added in v0.2.1

type Context3E[A any, B any] struct {
	// contains filtered or unexported fields
}

Context3E is a test context that allows for easy testing of two values and an error. This context contains two values and an error and provides methods to test equality and differences.

func Execute3E added in v0.2.1

func Execute3E[A any, B any](a A, b B, err error) *Context3E[A, B]

Execute3E is a helper function that returns a new context with two values and an error. Ideally, you'd just call the function you are testing directly: tests.Execute3A(struct.function()). This allows you to use the context methods to test the result: tests.Execute3A(struct.function()).NoError(t).Equal(t, expected).Equal(t, expected).

func (*Context3E[A, B]) Capture added in v0.2.2

func (ctx *Context3E[A, B]) Capture() (error, *Context2[A, B])

Capture returns the value.

func (*Context3E[A, B]) Error added in v0.2.1

func (ctx *Context3E[A, B]) Error(t testing.TB, opts ...Opt) *Context2[A, B]

Error checks that the value is an error.

func (*Context3E[A, B]) ErrorCode added in v0.2.2

func (ctx *Context3E[A, B]) ErrorCode(t testing.TB, expected errors.ErrorCode, opts ...Opt) *Context2[A, B]

ErrorCode checks that the value is an error and has the expected error code.

func (*Context3E[A, B]) MatchesError added in v0.2.1

func (ctx *Context3E[A, B]) MatchesError(t testing.TB, expected string, opts ...Opt) *Context2[A, B]

MatchesError checks that the value is an error and matches the expected error.

func (*Context3E[A, B]) NoError added in v0.2.1

func (ctx *Context3E[A, B]) NoError(t testing.TB, opts ...Opt) *Context2[A, B]

NoError checks that the value is not an error.

func (*Context3E[A, B]) Validate added in v0.2.1

func (ctx *Context3E[A, B]) Validate(t testing.TB, cb func(error)) *Context2[A, B]

Validate runs the given callback with the value.

type DiffInterface added in v0.2.0

type DiffInterface[E any] interface {
	Diff(E) string
}

DiffInterface is an interface that allows for custom diff checks.

type EqualityInterface added in v0.2.0

type EqualityInterface[E any] interface {
	Equals(E) bool
}

EqualityInterface is an interface that allows for custom equality checks.

type Opt added in v0.2.0

type Opt interface {
	// contains filtered or unexported methods
}

Opt is an option that can be used to modify the behavior of the underlying validator.

func CmpOption added in v0.2.2

func CmpOption(opt cmp.Option) Opt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳