assert

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package assert defines atomic assertions to be used in tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayNotEmpty

func ArrayNotEmpty(a Accumulator, response *http.Response)

ArrayNotEmpty checks that the response is not empty

func BookingStatus

func BookingStatus(a Accumulator, response *http.Response, expectedStatus string)

func CriticArrayNotEmpty

func CriticArrayNotEmpty(a Accumulator, response *http.Response)

CriticArrayNotEmpty checks that the response is not empty. A failure prevents the following assertions to be executed.

func CriticFormat

func CriticFormat(a Accumulator, request *http.Request, response *http.Response)

CriticFormat is the same as Format, but a failure prevents the following assertions to be executed.

func Format

func Format(a Accumulator, request *http.Request, response *http.Response)

Format checks if the response data has the expected format

func HeaderContains

func HeaderContains(a Accumulator, resp *http.Response, key, value string)

HeaderContains checks if a given key is present in header, with associated value

func JourneysArrivalRadius

func JourneysArrivalRadius(a Accumulator, request *http.Request, response *http.Response)

JourneysArrivalRadius checks that the response data respect the "arrivalRadius" query parameter

func JourneysCount

func JourneysCount(a Accumulator, request *http.Request, response *http.Response)

JourneysCount checks that the response data respect the "count" query parameter

func JourneysDepartureRadius

func JourneysDepartureRadius(a Accumulator, request *http.Request, response *http.Response)

JourneysDepartureRadius checks that the response data respect the "departureRadius" query parameter

func JourneysTimeDelta

func JourneysTimeDelta(a Accumulator, request *http.Request, response *http.Response)

JourneysTimeDelta checks that the response data respect the "timeDelta" query parameter

func MockOKStatusResponse

func MockOKStatusResponse() *http.Response

func OperatorFieldFormat

func OperatorFieldFormat(a Accumulator, response *http.Response)

OperatorFieldFormat checks that the response data has well formated "operator" field

func ShouldHaveSingleAssertionResult

func ShouldHaveSingleAssertionResult(t *testing.T, ar []Result)

func StatusCode

func StatusCode(a Accumulator, resp *http.Response, statusCode int)

StatusCode checks if a given response has an expected status code

StatusCode(*http.Response, int)

func StatusCodeOK

func StatusCodeOK(a Accumulator, resp *http.Response)

StatusCodeOK checks if a given response has status 200 OK

func UniqueIDs

func UniqueIDs(a Accumulator, response *http.Response)

UniqueIDs checks that all IDs (property "id"), if they exist, are unique.

Types

type Accumulator

type Accumulator interface {
	// Queue adds assertion to the queue for later execution
	Queue(...Assertion)

	// ExecuteAll executes assertions in sequence and stores the results.
	// If a CriticAssertion fails, execution is interrupted.
	ExecuteAll()

	// GetAssertionResults returns all results of executed assertions
	GetAssertionResults() []Result
}

An Accumulator can run assertions, store and retrieve the corresponding AssertionResults

type Assertion

type Assertion interface {
	Execute() error
	Describe() string
}

An Assertion is a unit test that can be executed and that can describe itself

type CriticAssertion

type CriticAssertion struct {
	Assertion
}

A CriticAssertion is an Assertion, which success is critic for the execution of subsequent assertions.

func Critic

func Critic(a Assertion) CriticAssertion

Critic converts an Assertion into a CriticAssertion

type DefaultAccumulator

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

DefaultAccumulator implements Asserter interface

func NewAccumulator

func NewAccumulator() *DefaultAccumulator

NewAccumulator inits a *DefaultAssertionAccu

func (*DefaultAccumulator) ExecuteAll

func (a *DefaultAccumulator) ExecuteAll()

ExecuteAll implements Accumulator.Run

func (*DefaultAccumulator) GetAssertionResults

func (a *DefaultAccumulator) GetAssertionResults() []Result

GetAssertionResults implements Accumulator.GetAssertionResults

func (*DefaultAccumulator) Queue

func (a *DefaultAccumulator) Queue(assertions ...Assertion)

Queue implements Accumulator.Queue.

type NopAssertion

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

A NopAssertion returns stored error when executed

func (NopAssertion) Describe

func (NopAssertion) Describe() string

Describe implements Assertion interface

func (NopAssertion) Execute

func (n NopAssertion) Execute() error

Execute implements Assertion interface

type Result

type Result struct {
	// Error, if any
	Err error

	// A string that summarizes the assertion
	AssertionDescription string
}

An Result stores data and metadata about the result of a single assertion

func CheckAPICallSuccess

func CheckAPICallSuccess(err error) Result

CheckAPICallSuccess checks if requesting an endpoint returned an error

func NewAssertionResult

func NewAssertionResult(err error, summary string) Result

NewAssertionResult initializes an AssertionResult

func (Result) Unwrap

func (ar Result) Unwrap() error

Unwrap returns AssertionResult underlying error (possibly nil)

Jump to

Keyboard shortcuts

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