validationtest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package validationtest contains helper functions for testing purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIsViolation deprecated

func AssertIsViolation(t *testing.T, err error, assert AssertViolationFunc) bool

Deprecated: use Assert instead.

func AssertIsViolationList deprecated

func AssertIsViolationList(t *testing.T, err error, assert AssertViolationListFunc) bool

Deprecated: use Assert instead.

func AssertOneViolationInList deprecated added in v0.5.2

func AssertOneViolationInList(t *testing.T, err error, assert AssertViolationFunc) bool

Deprecated: use Assert instead.

Types

type AssertViolationFunc

type AssertViolationFunc func(t *testing.T, violation validation.Violation) bool

type AssertViolationListFunc

type AssertViolationListFunc func(t *testing.T, violations []validation.Violation) bool

type Assertion added in v0.7.0

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

Assertion is a structure for testing an error for implementing validator violations.

func Assert added in v0.7.0

func Assert(t TestingT, err error) *Assertion

Assert creates a new Assertion for the error.

func (*Assertion) IsViolation added in v0.7.0

func (a *Assertion) IsViolation() *ViolationAssertion

IsViolation checks that err implements validation.Violation and returns ViolationAssertion for attributes assertions.

func (*Assertion) IsViolationList added in v0.7.0

func (a *Assertion) IsViolationList() *ViolationListAssertion

IsViolationList checks that err implements validation.IsViolationList and returns ViolationListAssertion for attributes assertions.

type TestingT added in v0.7.0

type TestingT interface {
	Helper()
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
}

TestingT is an interface wrapper around *testing.T.

type ViolationAssertion added in v0.7.0

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

ViolationAssertion is a structure for testing violation attributes.

func (*ViolationAssertion) Assert added in v0.7.0

func (a *ViolationAssertion) Assert(
	assert func(tb testing.TB, violation validation.Violation),
) *ViolationAssertion

Assert is used for the client-side assertion of the violation by a callback function.

func (*ViolationAssertion) EqualTo added in v0.7.0

EqualTo checks that the tested assertion is equal to the expected one.

func (*ViolationAssertion) EqualToError added in v0.7.0

func (a *ViolationAssertion) EqualToError(errString string) *ViolationAssertion

EqualToError checks that violation rendered to an error is equal to the expected one.

func (*ViolationAssertion) WithCode added in v0.7.0

func (a *ViolationAssertion) WithCode(code string) *ViolationAssertion

WithCode checks that violation has expected code.

func (*ViolationAssertion) WithMessage added in v0.7.0

func (a *ViolationAssertion) WithMessage(message string) *ViolationAssertion

WithMessage checks that violation has expected message.

func (*ViolationAssertion) WithPropertyPath added in v0.7.0

func (a *ViolationAssertion) WithPropertyPath(path string) *ViolationAssertion

WithPropertyPath checks that the tested violation has an expected property path.

type ViolationAttributes added in v0.7.0

type ViolationAttributes struct {
	Code         string
	Message      string
	PropertyPath string
}

ViolationAttributes are used to compare violation against expected values. An empty value is not compared.

type ViolationListAssertion added in v0.7.0

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

ViolationListAssertion is a structure for testing violation list attributes.

func (*ViolationListAssertion) Assert added in v0.7.0

func (a *ViolationListAssertion) Assert(
	assert func(tb testing.TB, violations []validation.Violation),
) *ViolationListAssertion

Assert is used for the client-side side assertion of violations by a callback function.

func (*ViolationListAssertion) HasViolationAt added in v0.7.0

func (a *ViolationListAssertion) HasViolationAt(index int) *ViolationAssertion

HasViolationAt checks that the violation list contains element at specific index and returns a ViolationAssertion to test it.

func (*ViolationListAssertion) WithAttributes added in v0.7.0

func (a *ViolationListAssertion) WithAttributes(violations ...ViolationAttributes) *ViolationListAssertion

WithAttributes checks that the violation list contains violations with the expected attributes in a given order. Empty values are not compared.

func (*ViolationListAssertion) WithCodes added in v0.7.0

func (a *ViolationListAssertion) WithCodes(codes ...string) *ViolationListAssertion

WithCodes checks that the violation list contains violations with specific codes in a given order.

func (*ViolationListAssertion) WithLen added in v0.7.0

WithLen checks that the violation list has exact length.

func (*ViolationListAssertion) WithOneViolation added in v0.7.0

func (a *ViolationListAssertion) WithOneViolation() *ViolationAssertion

WithOneViolation checks that the violation list contains exactly one violation and returns a ViolationAssertion to test it.

Jump to

Keyboard shortcuts

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