assert

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package assert contains the assertions used by the test runner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion interface {
	fact.Observer

	// Prepare is called to prepare the assertion for a new test.
	//
	// c is the comparator used to compare messages and other entities.
	Prepare(c compare.Comparator)

	// Ok returns true if the assertion passed.
	Ok() bool

	// BuildReport generates a report about the assertion.
	//
	// ok is true if the assertion is considered to have passed. This may not be
	// the same value as returned from Ok() when this assertion is used as
	// sub-assertion inside a composite.
	BuildReport(ok bool, r render.Renderer) *Report
}

Assertion is a predicate that checks if some specific critiria was met during the execution of a test.

func AllOf

func AllOf(subs ...Assertion) Assertion

AllOf returns an assertion that passes if all of the given sub-assertions pass.

func AnyOf

func AnyOf(subs ...Assertion) Assertion

AnyOf returns an assertion that passes if at least one of the given sub-assertions passes.

func CommandExecuted

func CommandExecuted(m dogma.Message) Assertion

CommandExecuted returns an assertion that passes if m is executed as a command.

func CommandTypeExecuted

func CommandTypeExecuted(m dogma.Message) Assertion

CommandTypeExecuted returns an assertion that passes if a message with the same type as m is executed as a command.

func EventRecorded

func EventRecorded(m dogma.Message) Assertion

EventRecorded returns an assertion that passes if m is recorded as an event.

func EventTypeRecorded

func EventTypeRecorded(m dogma.Message) Assertion

EventTypeRecorded returns an assertion that passes if a message witn the same type as m is recorded as an event.

func NoneOf

func NoneOf(subs ...Assertion) Assertion

NoneOf returns an assertion that passes if all of the given sub-assertions fail.

type CompositeAssertion

type CompositeAssertion struct {
	// Criteria is a brief description of the assertion's requirement to pass.
	Criteria string

	// SubAssertions is the set of assertions in the container.
	SubAssertions []Assertion

	// Predicate is a function that determines whether or not the assertion passes,
	// based on the number of child assertions that passed.
	//
	// It returns true if the assertion passed, and may optionally return a message
	// to be displayed in either case.
	Predicate func(int) (string, bool)
	// contains filtered or unexported fields
}

CompositeAssertion is an assertion that is a container for other assertions.

func (*CompositeAssertion) BuildReport

func (a *CompositeAssertion) BuildReport(ok bool, r render.Renderer) *Report

BuildReport generates a report about the assertion.

ok is true if the assertion is considered to have passed. This may not be the same value as returned from Ok() when this assertion is used as sub-assertion inside a composite.

func (*CompositeAssertion) Notify

func (a *CompositeAssertion) Notify(f fact.Fact)

Notify notifies the assertion of the occurrence of a fact.

func (*CompositeAssertion) Ok

func (a *CompositeAssertion) Ok() bool

Ok returns true if the assertion passed.

func (*CompositeAssertion) Prepare

func (a *CompositeAssertion) Prepare(c compare.Comparator)

Prepare is called to prepare the assertion for a new test.

c is the comparator used to compare messages and other entities.

type MessageAssertion

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

MessageAssertion asserts that a specific message is produced.

func (*MessageAssertion) BuildReport

func (a *MessageAssertion) BuildReport(ok bool, r render.Renderer) *Report

BuildReport generates a report about the assertion.

ok is true if the assertion is considered to have passed. This may not be the same value as returned from Ok() when this assertion is used as sub-assertion inside a composite.

func (*MessageAssertion) Notify

func (a *MessageAssertion) Notify(f fact.Fact)

Notify updates the assertion's state in response to a new fact.

func (*MessageAssertion) Ok

func (a *MessageAssertion) Ok() bool

Ok returns true if the assertion passed.

func (*MessageAssertion) Prepare

func (a *MessageAssertion) Prepare(c compare.Comparator)

Prepare is called to prepare the assertion for a new test.

c is the comparator used to compare messages and other entities.

type MessageTypeAssertion

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

MessageTypeAssertion asserts that a specific message is produced.

func (*MessageTypeAssertion) BuildReport

func (a *MessageTypeAssertion) BuildReport(ok bool, r render.Renderer) *Report

BuildReport generates a report about the assertion.

ok is true if the assertion is considered to have passed. This may not be the same value as returned from Ok() when this assertion is used as sub-assertion inside a composite.

func (*MessageTypeAssertion) Notify

func (a *MessageTypeAssertion) Notify(f fact.Fact)

Notify updates the assertion's state in response to a new fact.

func (*MessageTypeAssertion) Ok

func (a *MessageTypeAssertion) Ok() bool

Ok returns true if the assertion passed.

func (*MessageTypeAssertion) Prepare

func (a *MessageTypeAssertion) Prepare(c compare.Comparator)

Prepare is called to prepare the assertion for a new test.

c is the comparator used to compare messages and other entities.

type Report

type Report struct {
	// TreeOk is true if the "tree" that the assertion belongs to passed.
	TreeOk bool

	// Ok is true if this assertion passed.
	Ok bool

	// Criteria is a brief description of the assertion's requirement to pass.
	Criteria string

	// Outcome is a brief description of the outcome of the assertion.
	Outcome string

	// Explanation is a brief description of what actually happened during the test
	// as it relates to this assertion.
	Explanation string

	// Sections contains arbitrary "sections" that are added to the report by the
	// assertion.
	Sections []*ReportSection

	// SubReports contains the reports of any sub-assertions.
	SubReports []*Report
}

Report is a report on the outcome of an assertion.

func (*Report) Append

func (r *Report) Append(sr *Report)

Append adds sr as a sub-report of s.

func (*Report) Section

func (r *Report) Section(title string) *ReportSection

Section adds an arbitrary "section" to the report.

func (*Report) WriteTo

func (r *Report) WriteTo(next io.Writer) (_ int64, err error)

WriteTo writes the report to the given writer.

type ReportSection

type ReportSection struct {
	Title   string
	Content strings.Builder
}

ReportSection is a section of a report containing additional information about the assertion.

func (*ReportSection) Append

func (s *ReportSection) Append(f string, v ...interface{})

Append appends a line of text to the section's content.

func (*ReportSection) AppendListItem

func (s *ReportSection) AppendListItem(f string, v ...interface{})

AppendListItem appends a line of text prefixed with a bullet.

Jump to

Keyboard shortcuts

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