Skip to content

Commit

Permalink
Remove comment text.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Dec 20, 2019
1 parent 6005104 commit 4d2f98a
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 132 deletions.
27 changes: 15 additions & 12 deletions assert/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ type CompositeAssertion struct {
// 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.
// 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.
// It returns true if the assertion passed, and may optionally return a
// message to be displayed in either case.
Predicate func(int) (string, bool)

// ok is a pointer to the assertion's result. It is nil if Ok() has not been
// called.
// ok is a pointer to the assertion's result.
//
// It is nil if Ok() has not been called.
ok *bool

// outcome is the messagestring from the predicate function. It is populated by
// Ok().
// outcome is the messagestring from the predicate function.
//
// It is populated by Ok().
outcome string
}

// AllOf returns an assertion that passes if all of the given sub-assertions pass.
// AllOf returns an assertion that passes if all of the given sub-assertions
// pass.
func AllOf(subs ...Assertion) Assertion {
n := len(subs)

Expand Down Expand Up @@ -163,9 +166,9 @@ func (a *CompositeAssertion) 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.
// 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 (a *CompositeAssertion) BuildReport(ok bool, r render.Renderer) *Report {
a.Ok() // populate a.ok and a.outcome

Expand Down
30 changes: 17 additions & 13 deletions assert/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ type MessageAssertion struct {
// role.
best *envelope.Envelope

// sim is a ranking of the similarity between the type of the expected message,
// and the current best-match.
// sim is a ranking of the similarity between the type of the expected
// message, and the current best-match.
sim compare.TypeSimilarity

// equal is true if the best-match message compared as equal to the expected
// message. This can occur, and the assertion still fail, if the best-match
// message has an unexpected role.
equal bool

// tracker observers the handlers and messages that are involved in the test.
// tracker observers the handlers and messages that are involved in the
// test.
tracker tracker
}

// CommandExecuted returns an assertion that passes if m is executed as a command.
// CommandExecuted returns an assertion that passes if m is executed as a
// command.
func CommandExecuted(m dogma.Message) Assertion {
return &MessageAssertion{
expected: m,
Expand Down Expand Up @@ -82,9 +84,9 @@ func (a *MessageAssertion) 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.
// 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 (a *MessageAssertion) BuildReport(ok bool, r render.Renderer) *Report {
rep := &Report{
TreeOk: ok,
Expand Down Expand Up @@ -179,8 +181,9 @@ func (a *MessageAssertion) buildResultExpectedRole(r render.Renderer, rep *Repor
a.best.Origin.HandlerName,
a.best.Origin.HandlerType,
)
// note this language here is deliberately vague, it doesn't imply whether it
// currently is or isn't a pointer, just questions if it should be.
// note this language here is deliberately vague, it doesn't imply
// whether it currently is or isn't a pointer, just questions if it
// should be.
s.AppendListItem("check the message type, should it be a pointer?")
}

Expand Down Expand Up @@ -218,8 +221,8 @@ func (a *MessageAssertion) buildResultUnexpectedRole(r render.Renderer, rep *Rep
s.AppendListItem("verify that EventRecorded() is the correct assertion, did you mean CommandExecuted()?")
}

// the "best-match" is equal to the expected message. this means that only the
// roles were mismatched.
// the "best-match" is equal to the expected message. this means that only
// the roles were mismatched.
if a.equal {
rep.Explanation = inflect(
a.best.Role,
Expand All @@ -245,8 +248,9 @@ func (a *MessageAssertion) buildResultUnexpectedRole(r render.Renderer, rep *Rep
a.best.Origin.HandlerName,
a.best.Origin.HandlerType,
)
// note this language here is deliberately vague, it doesn't imply whether it
// currently is or isn't a pointer, just questions if it should be.
// note this language here is deliberately vague, it doesn't imply
// whether it currently is or isn't a pointer, just questions if it
// should be.
s.AppendListItem("check the message type, should it be a pointer?")
}

Expand Down
22 changes: 12 additions & 10 deletions assert/messagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ type MessageTypeAssertion struct {
// role.
best *envelope.Envelope

// sim is a ranking of the similarity between the type of the expected message,
// and the current best-match.
// sim is a ranking of the similarity between the type of the expected
// message, and the current best-match.
sim compare.TypeSimilarity

// tracker observers the handlers and messages that are involved in the test.
// tracker observers the handlers and messages that are involved in the
// test.
tracker tracker
}

Expand Down Expand Up @@ -72,9 +73,9 @@ func (a *MessageTypeAssertion) 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.
// 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 (a *MessageTypeAssertion) BuildReport(ok bool, r render.Renderer) *Report {
rep := &Report{
TreeOk: ok,
Expand Down Expand Up @@ -157,8 +158,8 @@ func (a *MessageTypeAssertion) buildResultExpectedRole(r render.Renderer, rep *R
a.best.Origin.HandlerName,
a.best.Origin.HandlerType,
)
// note this language here is deliberately vague, it doesn't imply whether it
// currently is or isn't a pointer, just questions if it should be.
// note this language here is deliberately vague, it doesn't imply whether
// it currently is or isn't a pointer, just questions if it should be.
s.AppendListItem("check the message type, should it be a pointer?")

a.buildDiff(rep)
Expand Down Expand Up @@ -196,8 +197,9 @@ func (a *MessageTypeAssertion) buildResultUnexpectedRole(r render.Renderer, rep
a.best.Origin.HandlerName,
a.best.Origin.HandlerType,
)
// note this language here is deliberately vague, it doesn't imply whether it
// currently is or isn't a pointer, just questions if it should be.
// note this language here is deliberately vague, it doesn't imply
// whether it currently is or isn't a pointer, just questions if it
// should be.
s.AppendListItem("check the message type, should it be a pointer?")

a.buildDiff(rep)
Expand Down
8 changes: 4 additions & 4 deletions assert/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ type Report struct {
// 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 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 contains arbitrary "sections" that are added to the report by
// the assertion.
Sections []*ReportSection

// SubReports contains the reports of any sub-assertions.
Expand Down
3 changes: 2 additions & 1 deletion assert/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ type tracker struct {
// total is the total number of messages that were produced.
total int

// produced is the number of messages of the expected role that were produced.
// produced is the number of messages of the expected role that were
// produced.
produced int

// engaged is the set of handlers that *could* have produced the expected
Expand Down
11 changes: 6 additions & 5 deletions compare/fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
"reflect"
)

// TypeSimilarity measures the similarity between two types.
// The higher the number, the more similar the types are.
// TypeSimilarity measures the similarity between two types. The higher the
// number, the more similar the types are.
type TypeSimilarity uint64

const (
// SameTypes is a TypeSimilarity value indicating that two types are identical.
// SameTypes is a TypeSimilarity value indicating that two types are
// identical.
SameTypes TypeSimilarity = math.MaxUint64

// UnrelatedTypes is a TypeSimilarity value that indicates that two types are
// totally unrelated.
// UnrelatedTypes is a TypeSimilarity value that indicates that two types
// are totally unrelated.
UnrelatedTypes TypeSimilarity = 0
)

Expand Down
3 changes: 2 additions & 1 deletion engine/controller/aggregate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func NewController(
}
}

// Identity returns the identity of the handler that is managed by this controller.
// Identity returns the identity of the handler that is managed by this
// controller.
func (c *Controller) Identity() configkit.Identity {
return c.identity
}
Expand Down
14 changes: 8 additions & 6 deletions engine/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import (

// Controller orchestrates the handling of a message by Dogma message handler.
type Controller interface {
// Identity returns the identity of the handler that is managed by this controller.
// Identity returns the identity of the handler that is managed by this
// controller.
Identity() configkit.Identity

// Type returns the name of the handler that is managed by this controller.
Type() configkit.HandlerType

// Tick instructs the controller to perform an implementation-defined "tick".
// Tick instructs the controller to perform an implementation-defined
// "tick".
//
// It returns the messages produced by the handler that need to be dispatched
// by the engine.
// It returns the messages produced by the handler that need to be
// dispatched by the engine.
//
// now is the current time, according to the engine, which may not match the
// system time.
Expand All @@ -32,8 +34,8 @@ type Controller interface {

// Handle handles a message.
//
// It returns the messages produced by the handler that need to be dispatched
// by the engine.
// It returns the messages produced by the handler that need to be
// dispatched by the engine.
//
// now is the current time, according to the engine, which may not match the
// system time.
Expand Down
3 changes: 2 additions & 1 deletion engine/controller/integration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func NewController(
}
}

// Identity returns the identity of the handler that is managed by this controller.
// Identity returns the identity of the handler that is managed by this
// controller.
func (c *Controller) Identity() configkit.Identity {
return c.identity
}
Expand Down
5 changes: 3 additions & 2 deletions engine/controller/process/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func NewController(
}
}

// Identity returns the identity of the handler that is managed by this controller.
// Identity returns the identity of the handler that is managed by this
// controller.
func (c *Controller) Identity() configkit.Identity {
return c.identity
}
Expand Down Expand Up @@ -219,7 +220,7 @@ func (c *Controller) routeTimeout(
return "", false, nil
}

// handle calls the appropriate method on the handler based on the message role.
// handle calls the appropriate method on the handler based on the message role.
func (c *Controller) handle(ctx context.Context, s *scope) error {
if s.env.Role == message.EventRole {
return c.handler.HandleEvent(ctx, s, s.env.Message)
Expand Down
3 changes: 2 additions & 1 deletion engine/controller/projection/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func NewController(
}
}

// Identity returns the identity of the handler that is managed by this controller.
// Identity returns the identity of the handler that is managed by this
// controller.
func (c *Controller) Identity() configkit.Identity {
return c.identity
}
Expand Down
17 changes: 9 additions & 8 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/dogmatiq/configkit"

"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/testkit/engine/controller"
Expand Down Expand Up @@ -204,9 +203,9 @@ func (e *Engine) dispatch(
e.controllers[env.Origin.HandlerName],
}
} else {
// for all other message types check to see the role matches the expected
// role from the configuration, and if so dispatch it to all of the handlers
// associated with that type
// for all other message types check to see the role matches the
// expected role from the configuration, and if so dispatch it to
// all of the handlers associated with that type
r, ok := e.roles[env.Type]
if !ok {
continue
Expand Down Expand Up @@ -285,17 +284,19 @@ func (e *Engine) handle(
return envs, err
}

// ExecuteCommand enqueues a command for execution. It panics if the command is
// not routed to any handlers.
// ExecuteCommand enqueues a command for execution.
//
// It panics if the command is not routed to any handlers.
func (e *Engine) ExecuteCommand(ctx context.Context, m dogma.Message) error {
t := message.TypeOf(m)
e.roles[t].MustBe(message.CommandRole)

return e.Dispatch(ctx, m)
}

// RecordEvent records the occurrence of an event. It is not an error to record
// an event that is not routed to any handlers.
// RecordEvent records the occurrence of an event.
//
// It is not an error to record an event that is not routed to any handlers.
func (e *Engine) RecordEvent(ctx context.Context, m dogma.Message) error {
return e.Dispatch(ctx, m)
}
Loading

0 comments on commit 4d2f98a

Please sign in to comment.