validationtest

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 5 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

This section is empty.

Types

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 github.com/muonsoft/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 github.com/muonsoft/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) WithError added in v0.13.0

func (a *ViolationAssertion) WithError(err error) *ViolationAssertion

WithError checks that violation has expected error.

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 {
	Error        error
	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) WithErrors added in v0.13.0

func (a *ViolationListAssertion) WithErrors(errs ...error) *ViolationListAssertion

WithErrors 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