Documentation
¶
Overview ¶
Package assert contains the assertions used by the test runner.
Index ¶
- type Assertion
- func AllOf(subs ...Assertion) Assertion
- func AnyOf(subs ...Assertion) Assertion
- func CommandExecuted(m dogma.Message) Assertion
- func CommandTypeExecuted(m dogma.Message) Assertion
- func EventRecorded(m dogma.Message) Assertion
- func EventTypeRecorded(m dogma.Message) Assertion
- func NoneOf(subs ...Assertion) Assertion
- func Should(cr string, fn func(AssertionContext) error) Assertion
- type AssertionContext
- type Report
- type ReportSection
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 a
// 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 AnyOf ¶
AnyOf returns an assertion that passes if at least one of the given sub-assertions passes.
func CommandExecuted ¶
CommandExecuted returns an assertion that passes if m is executed as a command.
func CommandTypeExecuted ¶
CommandTypeExecuted returns an assertion that passes if a message with the same type as m is executed as a command.
func EventRecorded ¶
EventRecorded returns an assertion that passes if m is recorded as an event.
func EventTypeRecorded ¶
EventTypeRecorded returns an assertion that passes if a message with the same type as m is recorded as an event.
func Should ¶ added in v0.4.0
func Should( cr string, fn func(AssertionContext) error, ) Assertion
Should returns an assertion that uses a user-defined function to check for specific criteria.
cr is a human-readable description of the expectation of the assertion. It should be phrased as an imperative statement, such as "insert a customer".
fn is the function that performs the assertion logic. It returns a non-nil error to indicate an assertion failure. It is passed an AssertionContext which contains dependencies and engine state that can be used to implement the assertion logic.
type AssertionContext ¶ added in v0.4.0
type AssertionContext struct {
// Comparator provides logic for comparing messages and application state.
Comparator compare.Comparator
// Facts is an ordered slice of the facts that occurred.
Facts []fact.Fact
}
AssertionContext is passed to user-defined assertion functions.
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) Section ¶
func (r *Report) Section(title string) *ReportSection
Section adds an arbitrary "section" to the report.
type ReportSection ¶
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.