assert

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 17 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

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

	// End is called once the test is complete.
	End()

	// 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 a
	// sub-assertion inside a composite.
	BuildReport(ok, verbose 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 with 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.

func Should added in v0.4.0

func Should(
	cr string,
	fn func(s *S),
) Assertion

Should returns an assertion that uses a user-defined function to check for specific criteria.

cr is a human-readable description of the "criteria" or the "expectation" that results in a passing assertion. It should be phrased as an imperative statement, such as "insert a customer".

fn is the function that performs the assertion logic. It is passed a *S value, which is analogous to Go's *testing.T, and provides an almost identical interface.

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.

type S added in v0.6.0

type S struct {
	// Comparator provides logic for comparing messages and application state.
	compare.Comparator

	// Facts is an ordered slice of the facts that occurred.
	Facts []fact.Fact
	// contains filtered or unexported fields
}

S is passed to assertions made via Should() to allow the user-defined criteria to be enforced. It is analogous the *testing.T type that is passed to tests in the native Go test runner.

func (*S) Cleanup added in v0.6.0

func (s *S) Cleanup(fn func())

Cleanup registers a function to be called when the test is complete. Cleanup functions will be called in last added, first called order.

func (*S) Error added in v0.6.0

func (s *S) Error(args ...interface{})

Error is equivalent to Log() followed by Fail().

func (*S) Errorf added in v0.6.0

func (s *S) Errorf(format string, args ...interface{})

Errorf is equivalent to Logf() followed by Fail().

func (*S) Fail added in v0.6.0

func (s *S) Fail()

Fail marks the function as having failed but continues execution.

func (*S) FailNow added in v0.6.0

func (s *S) FailNow()

FailNow marks the function as having failed and stops its execution.

func (*S) Failed added in v0.6.0

func (s *S) Failed() bool

Failed reports whether the test has failed.

func (*S) Fatal added in v0.6.0

func (s *S) Fatal(args ...interface{})

Fatal is equivalent to Log() followed by FailNow().

func (*S) Fatalf added in v0.6.0

func (s *S) Fatalf(format string, args ...interface{})

Fatalf is equivalent to Logf() followed by FailNow().

func (*S) Helper added in v0.6.0

func (s *S) Helper()

Helper marks the calling function as a test helper function.

It is a no-op in this implementation, but is included to increase compatibility with the *testing.T type.

func (*S) Log added in v0.6.0

func (s *S) Log(args ...interface{})

Log formats its arguments using default formatting, analogous to Println(), and records the text in the assertion report.

func (*S) Logf added in v0.6.0

func (s *S) Logf(format string, args ...interface{})

Logf formats its arguments according to the format, analogous to Printf(), and records the text in the assertion report.

func (*S) Name added in v0.6.0

func (s *S) Name() string

Name returns the name of the running test.

func (*S) Parallel added in v0.6.0

func (s *S) Parallel()

Parallel signals that this test is to be run in parallel with (and only with) other parallel tests.

It is a no-op in this implementation, but is included to increase compatibility with the *testing.T type.

func (*S) Skip added in v0.6.0

func (s *S) Skip(args ...interface{})

Skip is equivalent to Log() followed by SkipNow().

func (*S) SkipNow added in v0.6.0

func (s *S) SkipNow()

SkipNow marks the test as having been skipped and stops its execution.

func (*S) Skipf added in v0.6.0

func (s *S) Skipf(format string, args ...interface{})

Skipf is equivalent to Logf() followed by SkipNow().

func (*S) Skipped added in v0.6.0

func (s *S) Skipped() bool

Skipped reports whether the test was skipped.

Jump to

Keyboard shortcuts

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