Skip to content

Commit

Permalink
Move visitor stubs into configkit_test package.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Sep 26, 2024
1 parent f04a718 commit 3e04a2b
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 141 deletions.
5 changes: 2 additions & 3 deletions aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"

. "github.com/dogmatiq/configkit"
. "github.com/dogmatiq/configkit/internal/stubs"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
Expand Down Expand Up @@ -97,7 +96,7 @@ var _ = Describe("func FromAggregate()", func() {

Describe("func AcceptVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &VisitorStub{
v := &visitorStub{
VisitAggregateFunc: func(_ context.Context, c Aggregate) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand All @@ -111,7 +110,7 @@ var _ = Describe("func FromAggregate()", func() {

Describe("func AcceptRichVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &RichVisitorStub{
v := &richVisitorStub{
VisitRichAggregateFunc: func(_ context.Context, c RichAggregate) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand Down
5 changes: 2 additions & 3 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"

. "github.com/dogmatiq/configkit"
. "github.com/dogmatiq/configkit/internal/stubs"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
Expand Down Expand Up @@ -173,7 +172,7 @@ var _ = Describe("func FromApplication()", func() {

Describe("func AcceptVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &VisitorStub{
v := &visitorStub{
VisitApplicationFunc: func(_ context.Context, c Application) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand All @@ -187,7 +186,7 @@ var _ = Describe("func FromApplication()", func() {

Describe("func AcceptRichVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &RichVisitorStub{
v := &richVisitorStub{
VisitRichApplicationFunc: func(_ context.Context, c RichApplication) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand Down
9 changes: 4 additions & 5 deletions handlerset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"

. "github.com/dogmatiq/configkit"
. "github.com/dogmatiq/configkit/internal/stubs"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
Expand Down Expand Up @@ -304,7 +303,7 @@ var _ = Describe("type HandlerSet", func() {

err := set.AcceptVisitor(
context.Background(),
&VisitorStub{
&visitorStub{
VisitAggregateFunc: func(_ context.Context, cfg Aggregate) error {
Expect(cfg).To(BeIdenticalTo(aggregate))
visited = append(visited, cfg)
Expand All @@ -325,7 +324,7 @@ var _ = Describe("type HandlerSet", func() {
It("returns an error if one of the handlers fails", func() {
err := set.AcceptVisitor(
context.Background(),
&VisitorStub{
&visitorStub{
VisitProjectionFunc: func(_ context.Context, cfg Projection) error {
return errors.New("<error>")
},
Expand Down Expand Up @@ -848,7 +847,7 @@ var _ = Describe("type RichHandlerSet", func() {

err := set.AcceptRichVisitor(
context.Background(),
&RichVisitorStub{
&richVisitorStub{
VisitRichAggregateFunc: func(_ context.Context, cfg RichAggregate) error {
Expect(cfg).To(BeIdenticalTo(aggregate))
visited = append(visited, cfg)
Expand All @@ -869,7 +868,7 @@ var _ = Describe("type RichHandlerSet", func() {
It("returns an error if one of the handlers fails", func() {
err := set.AcceptRichVisitor(
context.Background(),
&RichVisitorStub{
&richVisitorStub{
VisitRichProjectionFunc: func(_ context.Context, cfg RichProjection) error {
return errors.New("<error>")
},
Expand Down
5 changes: 2 additions & 3 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"

. "github.com/dogmatiq/configkit"
. "github.com/dogmatiq/configkit/internal/stubs"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
Expand Down Expand Up @@ -97,7 +96,7 @@ var _ = Describe("func FromIntegration()", func() {

Describe("func AcceptVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &VisitorStub{
v := &visitorStub{
VisitIntegrationFunc: func(_ context.Context, c Integration) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand All @@ -111,7 +110,7 @@ var _ = Describe("func FromIntegration()", func() {

Describe("func AcceptRichVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &RichVisitorStub{
v := &richVisitorStub{
VisitRichIntegrationFunc: func(_ context.Context, c RichIntegration) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand Down
2 changes: 0 additions & 2 deletions internal/stubs/doc.go

This file was deleted.

119 changes: 0 additions & 119 deletions internal/stubs/visitor.go

This file was deleted.

5 changes: 2 additions & 3 deletions process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"

. "github.com/dogmatiq/configkit"
. "github.com/dogmatiq/configkit/internal/stubs"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
Expand Down Expand Up @@ -103,7 +102,7 @@ var _ = Describe("func FromProcess()", func() {

Describe("func AcceptVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &VisitorStub{
v := &visitorStub{
VisitProcessFunc: func(_ context.Context, c Process) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand All @@ -117,7 +116,7 @@ var _ = Describe("func FromProcess()", func() {

Describe("func AcceptRichVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &RichVisitorStub{
v := &richVisitorStub{
VisitRichProcessFunc: func(_ context.Context, c RichProcess) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand Down
5 changes: 2 additions & 3 deletions projection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"

. "github.com/dogmatiq/configkit"
. "github.com/dogmatiq/configkit/internal/stubs"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
Expand Down Expand Up @@ -102,7 +101,7 @@ var _ = Describe("func FromProjection()", func() {

Describe("func AcceptVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &VisitorStub{
v := &visitorStub{
VisitProjectionFunc: func(_ context.Context, c Projection) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand All @@ -116,7 +115,7 @@ var _ = Describe("func FromProjection()", func() {

Describe("func AcceptRichVisitor()", func() {
It("calls the appropriate method on the visitor", func() {
v := &RichVisitorStub{
v := &richVisitorStub{
VisitRichProjectionFunc: func(_ context.Context, c RichProjection) error {
Expect(c).To(BeIdenticalTo(cfg))
return errors.New("<error>")
Expand Down
95 changes: 95 additions & 0 deletions visitor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package configkit_test

import (
"context"

. "github.com/dogmatiq/configkit"
)

// visitorStub is a test implementation of [configkit.Visitor].
type visitorStub struct {
VisitApplicationFunc func(context.Context, Application) error
VisitAggregateFunc func(context.Context, Aggregate) error
VisitProcessFunc func(context.Context, Process) error
VisitIntegrationFunc func(context.Context, Integration) error
VisitProjectionFunc func(context.Context, Projection) error
}

func (v *visitorStub) VisitApplication(ctx context.Context, cfg Application) error {
if v.VisitApplicationFunc != nil {
return v.VisitApplicationFunc(ctx, cfg)
}
return cfg.Handlers().AcceptVisitor(ctx, v)
}

func (v *visitorStub) VisitAggregate(ctx context.Context, cfg Aggregate) error {
if v.VisitAggregateFunc == nil {
return nil
}
return v.VisitAggregateFunc(ctx, cfg)
}

func (v *visitorStub) VisitProcess(ctx context.Context, cfg Process) error {
if v.VisitProcessFunc == nil {
return nil
}
return v.VisitProcessFunc(ctx, cfg)
}

func (v *visitorStub) VisitIntegration(ctx context.Context, cfg Integration) error {
if v.VisitIntegrationFunc == nil {
return nil
}
return v.VisitIntegrationFunc(ctx, cfg)
}

func (v *visitorStub) VisitProjection(ctx context.Context, cfg Projection) error {
if v.VisitProjectionFunc == nil {
return nil
}
return v.VisitProjectionFunc(ctx, cfg)
}

// richVisitorStub is a test implementation of [configkit.RichVisitor].
type richVisitorStub struct {
VisitRichApplicationFunc func(context.Context, RichApplication) error
VisitRichAggregateFunc func(context.Context, RichAggregate) error
VisitRichProcessFunc func(context.Context, RichProcess) error
VisitRichIntegrationFunc func(context.Context, RichIntegration) error
VisitRichProjectionFunc func(context.Context, RichProjection) error
}

func (v *richVisitorStub) VisitRichApplication(ctx context.Context, cfg RichApplication) error {
if v.VisitRichApplicationFunc != nil {
return v.VisitRichApplicationFunc(ctx, cfg)
}
return cfg.RichHandlers().AcceptRichVisitor(ctx, v)
}

func (v *richVisitorStub) VisitRichAggregate(ctx context.Context, cfg RichAggregate) error {
if v.VisitRichAggregateFunc == nil {
return nil
}
return v.VisitRichAggregateFunc(ctx, cfg)
}

func (v *richVisitorStub) VisitRichProcess(ctx context.Context, cfg RichProcess) error {
if v.VisitRichProcessFunc == nil {
return nil
}
return v.VisitRichProcessFunc(ctx, cfg)
}

func (v *richVisitorStub) VisitRichIntegration(ctx context.Context, cfg RichIntegration) error {
if v.VisitRichIntegrationFunc == nil {
return nil
}
return v.VisitRichIntegrationFunc(ctx, cfg)
}

func (v *richVisitorStub) VisitRichProjection(ctx context.Context, cfg RichProjection) error {
if v.VisitRichProjectionFunc == nil {
return nil
}
return v.VisitRichProjectionFunc(ctx, cfg)
}

0 comments on commit 3e04a2b

Please sign in to comment.