From 2528533b4d631fd602a643fdc20fb18cf5dff992 Mon Sep 17 00:00:00 2001 From: James Harris Date: Sat, 5 Oct 2024 20:10:04 +1000 Subject: [PATCH] Remove `message` package and replace with `enginekit/message`. --- aggregate.go | 2 +- aggregate_test.go | 2 +- application.go | 2 +- application_test.go | 2 +- entity.go | 2 +- entity_test.go | 2 +- go.mod | 2 +- go.sum | 4 +- handler.go | 6 +- handlerset.go | 2 +- handlerset_test.go | 2 +- handlertype.go | 6 +- handlertype_test.go | 2 +- integration.go | 2 +- integration_test.go | 2 +- marshal.go | 37 +- marshal_test.go | 4 +- message/doc.go | 3 - message/ginkgo_test.go | 15 - message/kind.go | 238 ------------ message/kind_test.go | 410 --------------------- message/name.go | 83 ----- message/name_test.go | 131 ------- message/type.go | 99 ----- message/type_test.go | 125 ------- process.go | 2 +- process_test.go | 2 +- projection.go | 2 +- projection_test.go | 2 +- static/analysis.go | 4 +- static/app_test.go | 2 +- static/entity.go | 2 +- static/handler_conditional_routes_test.go | 2 +- static/handler_dynamic_routes_test.go | 2 +- static/handler_unregistered_routes_test.go | 2 +- string.go | 6 +- visualization/dot/generator.go | 4 +- visualization/dot/style.go | 2 +- 38 files changed, 50 insertions(+), 1169 deletions(-) delete mode 100644 message/doc.go delete mode 100644 message/ginkgo_test.go delete mode 100644 message/kind.go delete mode 100644 message/kind_test.go delete mode 100644 message/name.go delete mode 100644 message/name_test.go delete mode 100644 message/type.go delete mode 100644 message/type_test.go diff --git a/aggregate.go b/aggregate.go index f1b1dc13..573b787d 100644 --- a/aggregate.go +++ b/aggregate.go @@ -5,8 +5,8 @@ import ( "reflect" "github.com/dogmatiq/configkit/internal/typename/goreflect" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" + "github.com/dogmatiq/enginekit/message" ) // Aggregate is an interface that represents the configuration of a Dogma diff --git a/aggregate_test.go b/aggregate_test.go index c15dae39..e4b51da4 100644 --- a/aggregate_test.go +++ b/aggregate_test.go @@ -6,9 +6,9 @@ import ( "reflect" . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" diff --git a/application.go b/application.go index 75105470..6102ac17 100644 --- a/application.go +++ b/application.go @@ -6,8 +6,8 @@ import ( "github.com/dogmatiq/configkit/internal/typename/goreflect" "github.com/dogmatiq/configkit/internal/validation" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" + "github.com/dogmatiq/enginekit/message" ) // Application is an interface that represents the configuration of a Dogma diff --git a/application_test.go b/application_test.go index 33c5a859..25ad80cd 100644 --- a/application_test.go +++ b/application_test.go @@ -6,9 +6,9 @@ import ( "reflect" . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" diff --git a/entity.go b/entity.go index b5747114..3b32f8f7 100644 --- a/entity.go +++ b/entity.go @@ -7,7 +7,7 @@ import ( "reflect" "slices" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" ) // Entity is an interface that represents the configuration of a Dogma "entity" diff --git a/entity_test.go b/entity_test.go index 3787b70b..0f325c21 100644 --- a/entity_test.go +++ b/entity_test.go @@ -4,8 +4,8 @@ import ( "maps" . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" diff --git a/go.mod b/go.mod index 83028b02..6f314e18 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.1 require ( github.com/dogmatiq/aureus v0.1.0 github.com/dogmatiq/dogma v0.15.0 - github.com/dogmatiq/enginekit v0.16.0 + github.com/dogmatiq/enginekit v0.16.1-0.20241005100116-c3335230d56f github.com/dogmatiq/iago v0.4.0 github.com/emicklei/dot v1.6.2 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index 7f720267..f83d889d 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/dogmatiq/dapper v0.6.0 h1:hnWUsjnt3nUiC9hmkPvuxrnMd7fYNz1i+/GS3gOx0Xs github.com/dogmatiq/dapper v0.6.0/go.mod h1:ubRHWzt73s0MsPpGhWvnfW/Z/1YPnrkCsQv6CUOZVEw= github.com/dogmatiq/dogma v0.15.0 h1:aXOTd2K4wLvlwHc1D9OsFREp0BusNJ9o9KssxURftmg= github.com/dogmatiq/dogma v0.15.0/go.mod h1:TF6xisRxQ2RE3JQwFr6MCI4nWLKQQp7KRWXVHOq9K0k= -github.com/dogmatiq/enginekit v0.16.0 h1:1+Fr0117jihoiY2SABsSAGhJYLi8DeNv35rR8PWgBfk= -github.com/dogmatiq/enginekit v0.16.0/go.mod h1:nODdKEljyHQHDRlwQrKD3NCJ/4y1jFFKYDwJ0yeHcVo= +github.com/dogmatiq/enginekit v0.16.1-0.20241005100116-c3335230d56f h1:U00wlzp2h0VLhQCk6AyCZ1oI0UW1iFvmxwOqvuuL/E4= +github.com/dogmatiq/enginekit v0.16.1-0.20241005100116-c3335230d56f/go.mod h1:nODdKEljyHQHDRlwQrKD3NCJ/4y1jFFKYDwJ0yeHcVo= github.com/dogmatiq/iago v0.4.0 h1:57nZqVT34IZxtCZEW/RFif7DNUEjMXgevfr/Mmd0N8I= github.com/dogmatiq/iago v0.4.0/go.mod h1:fishMWBtzYcjgis6d873VTv9kFm/wHYLOzOyO9ECBDc= github.com/dogmatiq/jumble v0.1.0 h1:Cb3ExfxY+AoUP4G9/sOwoOdYX8o+kOLK8+dhXAry+QA= diff --git a/handler.go b/handler.go index 528eae4c..dcf955b5 100644 --- a/handler.go +++ b/handler.go @@ -5,8 +5,8 @@ import ( "reflect" "github.com/dogmatiq/configkit/internal/validation" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" + "github.com/dogmatiq/enginekit/message" "golang.org/x/text/cases" "golang.org/x/text/language" ) @@ -185,8 +185,8 @@ func mustHaveProducerRoute( } } - verb := message.MapKind(kind, "execute", "record", "schedule") - routeFunc := message.MapKind(kind, "ExecutesCommand", "RecordsEvent", "SchedulesTimeout") + verb := message.MapByKind(kind, "execute", "record", "schedule") + routeFunc := message.MapByKind(kind, "ExecutesCommand", "RecordsEvent", "SchedulesTimeout") validation.Panicf( `%s is not configured to %s any %ss, at least one %s() route must be added within Configure()`, diff --git a/handlerset.go b/handlerset.go index 37fa31c6..131c402d 100644 --- a/handlerset.go +++ b/handlerset.go @@ -3,7 +3,7 @@ package configkit import ( "context" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" ) // HandlerSet is a collection of handlers. diff --git a/handlerset_test.go b/handlerset_test.go index 22241747..300cb2b0 100644 --- a/handlerset_test.go +++ b/handlerset_test.go @@ -5,9 +5,9 @@ import ( "errors" . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" diff --git a/handlertype.go b/handlertype.go index fb829cd1..f185fb1d 100644 --- a/handlertype.go +++ b/handlertype.go @@ -6,7 +6,7 @@ import ( "slices" "github.com/dogmatiq/configkit/internal/validation" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" ) // HandlerType is an enumeration of the types of handlers. @@ -222,7 +222,7 @@ func (t *HandlerType) UnmarshalBinary(data []byte) error { // ConsumersOf returns the handler types that can consume messages of kind k. func ConsumersOf(k message.Kind) []HandlerType { - return message.MapKind( + return message.MapByKind( k, []HandlerType{AggregateHandlerType, IntegrationHandlerType}, []HandlerType{ProcessHandlerType, ProjectionHandlerType}, @@ -232,7 +232,7 @@ func ConsumersOf(k message.Kind) []HandlerType { // ProducersOf returns the handler types that can produces messages of kind k. func ProducersOf(k message.Kind) []HandlerType { - return message.MapKind( + return message.MapByKind( k, []HandlerType{ProcessHandlerType}, []HandlerType{AggregateHandlerType, IntegrationHandlerType}, diff --git a/handlertype_test.go b/handlertype_test.go index 34fe922e..974075b8 100644 --- a/handlertype_test.go +++ b/handlertype_test.go @@ -2,7 +2,7 @@ package configkit_test import ( . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/integration.go b/integration.go index 34cb5863..b9f1e8d2 100644 --- a/integration.go +++ b/integration.go @@ -5,8 +5,8 @@ import ( "reflect" "github.com/dogmatiq/configkit/internal/typename/goreflect" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" + "github.com/dogmatiq/enginekit/message" ) // Integration is an interface that represents the configuration of a Dogma diff --git a/integration_test.go b/integration_test.go index 6630fbfa..e3dce631 100644 --- a/integration_test.go +++ b/integration_test.go @@ -6,9 +6,9 @@ import ( "reflect" . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" diff --git a/marshal.go b/marshal.go index 3f57da50..197d2474 100644 --- a/marshal.go +++ b/marshal.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" "github.com/dogmatiq/enginekit/protobuf/configpb" "github.com/dogmatiq/enginekit/protobuf/identitypb" "github.com/dogmatiq/enginekit/protobuf/uuidpb" @@ -28,11 +28,6 @@ func ToProto(app Application) (*configpb.Application, error) { } for n, em := range app.MessageNames() { - nOut, err := n.MarshalText() - if err != nil { - return nil, err - } - kOut, err := marshalMessageKind(em.Kind) if err != nil { return nil, err @@ -41,7 +36,7 @@ func ToProto(app Application) (*configpb.Application, error) { if out.Messages == nil { out.Messages = map[string]configpb.MessageKind{} } - out.Messages[string(nOut)] = kOut + out.Messages[string(n)] = kOut } for _, h := range app.Handlers() { @@ -74,17 +69,12 @@ func FromProto(app *configpb.Application) (Application, error) { kinds := map[message.Name]message.Kind{} for n, k := range app.GetMessages() { - var nOut message.Name - if err := nOut.UnmarshalText([]byte(n)); err != nil { - return nil, err - } - kOut, err := unmarshalMessageKind(k) if err != nil { return nil, err } - kinds[nOut] = kOut + kinds[message.Name(n)] = kOut } for _, h := range app.GetHandlers() { @@ -125,16 +115,15 @@ func marshalHandler(in Handler) (*configpb.Handler, error) { } for n, em := range in.MessageNames() { - if out.Messages == nil { - out.Messages = map[string]*configpb.MessageUsage{} + if n == "" { + return nil, errors.New("message name is empty") } - name, err := n.MarshalText() - if err != nil { - return nil, err + if out.Messages == nil { + out.Messages = map[string]*configpb.MessageUsage{} } - key := string(name) + key := string(n) usage, ok := out.Messages[key] if !ok { @@ -181,12 +170,8 @@ func unmarshalHandler( } for n, usage := range in.GetMessages() { - var nOut message.Name - if err := nOut.UnmarshalText([]byte(n)); err != nil { - return nil, err - } - - k, ok := kinds[nOut] + nOut := message.Name(n) + kOut, ok := kinds[nOut] if !ok { return nil, fmt.Errorf("message name %s as no associated message kind", n) } @@ -198,7 +183,7 @@ func unmarshalHandler( out.names.Update( nOut, func(n message.Name, em *EntityMessage) { - em.Kind = k + em.Kind = kOut if usage.IsProduced { em.IsProduced = true diff --git a/marshal_test.go b/marshal_test.go index 6f0397c9..331d7974 100644 --- a/marshal_test.go +++ b/marshal_test.go @@ -2,8 +2,8 @@ package configkit import ( //revive:disable:dot-imports - "github.com/dogmatiq/configkit/message" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" "github.com/dogmatiq/enginekit/protobuf/configpb" "github.com/dogmatiq/enginekit/protobuf/identitypb" "github.com/dogmatiq/enginekit/protobuf/uuidpb" @@ -136,7 +136,7 @@ var _ = Describe("func marshalHandler()", func() { }) It("returns an error if there is an invalid message name", func() { - handler.names[message.Name{}] = EntityMessage{} + handler.names[""] = EntityMessage{} _, err := marshalHandler(handler) Expect(err).Should(HaveOccurred()) diff --git a/message/doc.go b/message/doc.go deleted file mode 100644 index ba6f5ff0..00000000 --- a/message/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package message provides utilities for representing information about Dogma -// messages and their use within an application. -package message diff --git a/message/ginkgo_test.go b/message/ginkgo_test.go deleted file mode 100644 index eb50d640..00000000 --- a/message/ginkgo_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package message_test - -import ( - "reflect" - "testing" - - "github.com/onsi/ginkgo" - "github.com/onsi/gomega" -) - -func TestSuite(t *testing.T) { - type tag struct{} - gomega.RegisterFailHandler(ginkgo.Fail) - ginkgo.RunSpecs(t, reflect.TypeOf(tag{}).PkgPath()) -} diff --git a/message/kind.go b/message/kind.go deleted file mode 100644 index f416f7b1..00000000 --- a/message/kind.go +++ /dev/null @@ -1,238 +0,0 @@ -package message - -import ( - "fmt" - "reflect" - - "github.com/dogmatiq/dogma" -) - -// Kind is an enumeration of the different kinds of messages. -// -// It is similar to a [Role], however it is not tied to a specific application. -type Kind int - -const ( - // CommandKind is a [dogma.Message] that also implements [dogma.Command]. - CommandKind Kind = iota - - // EventKind is a [dogma.Message] that also implements [dogma.Event]. - EventKind - - // TimeoutKind is a [dogma.Message] that also implements [dogma.Timeout]. - TimeoutKind -) - -// Symbol returns a character that identifies the message kind when displaying -// message types. -func (k Kind) Symbol() string { - return MapKind(k, "?", "!", "@") -} - -func (k Kind) String() string { - return MapKind(k, "command", "event", "timeout") -} - -// KindFor returns the [Kind] of the message with type T. -// -// It panics if T does not implement [dogma.Command], [dogma.Event] or -// [dogma.Timeout]. -func KindFor[T dogma.Message]() Kind { - return kindFromReflect( - reflect.TypeFor[T](), - ) -} - -// KindOf returns the [Kind] of m. -func KindOf(m dogma.Message) Kind { - switch m.(type) { - case dogma.Command: - return CommandKind - case dogma.Event: - return EventKind - case dogma.Timeout: - return TimeoutKind - default: - panic(fmt.Sprintf("%T does not implement dogma.Command, dogma.Event or dogma.Timeout", m)) - } -} - -func kindFromReflect(rt reflect.Type) Kind { - if rt.Implements(commandInterface) { - return CommandKind - } - - if rt.Implements(eventInterface) { - return EventKind - } - - if rt.Implements(timeoutInterface) { - return TimeoutKind - } - - panic(fmt.Sprintf("%s does not implement dogma.Command, dogma.Event or dogma.Timeout", rt)) -} - -var ( - commandInterface = reflect.TypeFor[dogma.Command]() - eventInterface = reflect.TypeFor[dogma.Event]() - timeoutInterface = reflect.TypeFor[dogma.Timeout]() -) - -// Switch invokes one of the provided functions based on the [Kind] of m. -// -// It provides a compile-time guarantee that all kinds are handled, even if new -// [Kind] values are added in the future. -// -// It panics with a meaningful message if the function associated with m's kind -// is nil. -// -// It panics if m does not implement [dogma.Command], [dogma.Event] or -// [dogma.Timeout]. -func Switch( - m dogma.Message, - command func(dogma.Command), - event func(dogma.Event), - timeout func(dogma.Timeout), -) { - switch m := m.(type) { - case dogma.Command: - if command == nil { - panic("no case function was provided for dogma.Command messages") - } - command(m) - case dogma.Event: - if event == nil { - panic("no case function was provided for dogma.Event messages") - } - event(m) - case dogma.Timeout: - if timeout == nil { - panic("no case function was provided for dogma.Timeout messages") - } - timeout(m) - default: - panic(fmt.Sprintf( - "%T implements dogma.Message, but it does not implement dogma.Command, dogma.Event or dogma.Timeout", - m, - )) - } -} - -// Map invokes one of the provided functions based on the [Kind] of m, and -// returns the result. -// -// It provides a compile-time guarantee that all kinds are handled, even if new -// [Kind] values are added in the future. -// -// It panics with a meaningful message if the function associated with m's kind -// is nil. -// -// It panics if m does not implement [dogma.Command], [dogma.Event] or -// [dogma.Timeout]. -func Map[T any]( - m dogma.Message, - command func(dogma.Command) T, - event func(dogma.Event) T, - timeout func(dogma.Timeout) T, -) (result T) { - Switch( - m, - mapFunc(command, &result), - mapFunc(event, &result), - mapFunc(timeout, &result), - ) - - return result -} - -func mapFunc[K dogma.Message, T any](fn func(K) T, v *T) func(K) { - if fn == nil { - return nil - } - return func(m K) { - *v = fn(m) - } -} - -// TryMap invokes one of the provided functions based on the [Kind] of m, and -// returns the result and error. -// -// It provides a compile-time guarantee that all kinds are handled, even if new -// [Kind] values are added in the future. -// -// It panics with a meaningful message if the function associated with m's kind -// is nil. -// -// It panics if m does not implement [dogma.Command], [dogma.Event] or -// [dogma.Timeout]. -func TryMap[T any]( - m dogma.Message, - command func(dogma.Command) (T, error), - event func(dogma.Event) (T, error), - timeout func(dogma.Timeout) (T, error), -) (result T, err error) { - Switch( - m, - tryMapFunc(command, &result, &err), - tryMapFunc(event, &result, &err), - tryMapFunc(timeout, &result, &err), - ) - - return result, err -} - -func tryMapFunc[K dogma.Message, T any]( - fn func(K) (T, error), - v *T, - err *error, -) func(K) { - if fn == nil { - return nil - } - return func(m K) { - *v, *err = fn(m) - } -} - -// SwitchKind invokes one of the provided functions based on k. -// -// It provides a compile-time guarantee that all possible values are handled, -// even if new [Kind] values are added in the future. -// -// It panics with a meaningful message if the function associated with k. -// -// It panics if k is not a valid [Kind]. -func SwitchKind( - k Kind, - command func(), - event func(), - timeout func(), -) { - fn := MapKind(k, command, event, timeout) - - if fn == nil { - panic(fmt.Sprintf("no case function was provided for the %q kind", k)) - } - - fn() -} - -// MapKind maps k to a value of type T. -// -// It provides a compile-time guarantee that all possible values are handled, -// even if new [Kind] values are added in the future. -// -// It panics if k is not a valid [Kind]. -func MapKind[T any](k Kind, command, event, timeout T) (result T) { - switch k { - case CommandKind: - return command - case EventKind: - return event - case TimeoutKind: - return timeout - default: - panic("invalid kind") - } -} diff --git a/message/kind_test.go b/message/kind_test.go deleted file mode 100644 index ec1e9a85..00000000 --- a/message/kind_test.go +++ /dev/null @@ -1,410 +0,0 @@ -package message_test - -import ( - "errors" - "testing" - - . "github.com/dogmatiq/configkit/message" - "github.com/dogmatiq/dogma" - . "github.com/dogmatiq/enginekit/enginetest/stubs" -) - -func TestKindOf(t *testing.T) { - cases := []struct { - Message dogma.Message - Want Kind - }{ - {CommandA1, CommandKind}, - {EventA1, EventKind}, - {TimeoutA1, TimeoutKind}, - } - - for _, c := range cases { - got := KindOf(c.Message) - if got != c.Want { - t.Fatalf("unexpected result: got %q, want %q", got, c.Want) - } - } - - t.Run("it panics if the message does not implement any of the more specific interfaces", func(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("expected a panic") - } - }() - - KindOf(nil) - }) -} - -func TestKindFor(t *testing.T) { - if want, got := CommandKind, KindFor[CommandStub[TypeA]](); got != want { - t.Fatalf("unexpected result: got %q, want %q", got, want) - } - - if want, got := EventKind, KindFor[EventStub[TypeA]](); got != want { - t.Fatalf("unexpected result: got %q, want %q", got, want) - } - - if want, got := TimeoutKind, KindFor[TimeoutStub[TypeA]](); got != want { - t.Fatalf("unexpected result: got %q, want %q", got, want) - } - - t.Run("it panics if the message does not implement any of the more specific interfaces", func(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("expected a panic") - } - }() - - KindFor[dogma.Message]() - }) -} - -func TestKind(t *testing.T) { - t.Run("symbol", func(t *testing.T) { - cases := []struct { - Kind Kind - Want string - }{ - {CommandKind, "?"}, - {EventKind, "!"}, - {TimeoutKind, "@"}, - } - - for _, c := range cases { - got := c.Kind.Symbol() - if got != c.Want { - t.Fatalf("unexpected result: got %q, want %q", got, c.Want) - } - } - }) - - t.Run("string", func(t *testing.T) { - cases := []struct { - Kind Kind - Want string - }{ - {CommandKind, "command"}, - {EventKind, "event"}, - {TimeoutKind, "timeout"}, - } - - for _, c := range cases { - got := c.Kind.String() - if got != c.Want { - t.Fatalf("unexpected result: got %q, want %q", got, c.Want) - } - } - }) -} - -func TestSwitch(t *testing.T) { - t.Run("when the message is a command", func(t *testing.T) { - var message dogma.Command - - Switch( - CommandA1, - func(m dogma.Command) { message = m }, - func(m dogma.Event) { t.Fatal("unexpected call to event case") }, - func(m dogma.Timeout) { t.Fatal("unexpected call to timeout case") }, - ) - - if message != CommandA1 { - t.Fatal("command case was not called with the expected message") - } - }) - - t.Run("when the message is an event", func(t *testing.T) { - var message dogma.Event - - Switch( - EventA1, - func(m dogma.Command) { t.Fatal("unexpected call to command case") }, - func(m dogma.Event) { message = m }, - func(m dogma.Timeout) { t.Fatal("unexpected call to timeout case") }, - ) - - if message != EventA1 { - t.Fatal("event case was not called with the expected message") - } - }) - - t.Run("when the message is a timeout", func(t *testing.T) { - var message dogma.Timeout - - Switch( - TimeoutA1, - func(m dogma.Command) { t.Fatal("unexpected call to command case") }, - func(m dogma.Event) { t.Fatal("unexpected call to event case") }, - func(m dogma.Timeout) { message = m }, - ) - - if message != TimeoutA1 { - t.Fatal("timeout case was not called with the expected message") - } - }) - - t.Run("it panics when the associated function is nil", func(t *testing.T) { - cases := []struct { - Message dogma.Message - Want string - }{ - {CommandA1, `no case function was provided for dogma.Command messages`}, - {EventA1, `no case function was provided for dogma.Event messages`}, - {TimeoutA1, `no case function was provided for dogma.Timeout messages`}, - } - - for _, c := range cases { - func() { - defer func() { - if got := recover(); got != c.Want { - t.Fatalf("unexpected panic: got %q, want %q", got, c.Want) - } - }() - - Switch(c.Message, nil, nil, nil) - }() - } - }) - - t.Run("it panics if the message does not implement any of the more specific interfaces", func(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("expected a panic") - } - }() - - Switch( - nil, - func(m dogma.Command) { t.Fatal("unexpected call to command case") }, - func(m dogma.Event) { t.Fatal("unexpected call to event case") }, - func(m dogma.Timeout) { t.Fatal("unexpected call to timeout case") }, - ) - }) -} - -func TestMap(t *testing.T) { - cases := []struct { - Message dogma.Message - Want string - }{ - {CommandA1, "command"}, - {EventA1, "event"}, - {TimeoutA1, "timeout"}, - } - - for _, c := range cases { - got := Map( - c.Message, - func(m dogma.Command) string { return "command" }, - func(m dogma.Event) string { return "event" }, - func(m dogma.Timeout) string { return "timeout" }, - ) - - if got != c.Want { - t.Fatalf("unexpected result: got %q, want %q", got, c.Want) - } - } - - t.Run("it panics when the associated function is nil", func(t *testing.T) { - cases := []struct { - Message dogma.Message - Want string - }{ - {CommandA1, `no case function was provided for dogma.Command messages`}, - {EventA1, `no case function was provided for dogma.Event messages`}, - {TimeoutA1, `no case function was provided for dogma.Timeout messages`}, - } - - for _, c := range cases { - func() { - defer func() { - if got := recover(); got != c.Want { - t.Fatalf("unexpected panic: got %q, want %q", got, c.Want) - } - }() - - Map[int](c.Message, nil, nil, nil) - }() - } - }) - - t.Run("it panics if the message does not implement any of the more specific interfaces", func(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("expected a panic") - } - }() - - Map( - nil, - func(m dogma.Command) string { t.Fatal("unexpected call to command case"); return "" }, - func(m dogma.Event) string { t.Fatal("unexpected call to event case"); return "" }, - func(m dogma.Timeout) string { t.Fatal("unexpected call to timeout case"); return "" }, - ) - }) -} - -func TestTryMap(t *testing.T) { - cases := []struct { - Message dogma.Message - Want string - }{ - {CommandA1, "command"}, - {EventA1, "event"}, - {TimeoutA1, "timeout"}, - } - - for _, c := range cases { - got, gotErr := TryMap( - c.Message, - func(m dogma.Command) (string, error) { return "command", errors.New("command") }, - func(m dogma.Event) (string, error) { return "event", errors.New("event") }, - func(m dogma.Timeout) (string, error) { return "timeout", errors.New("timeout") }, - ) - - if got != c.Want { - t.Fatalf("unexpected result: got %q, want %q", got, c.Want) - } - - if gotErr == nil { - t.Fatal("expected an error") - } - - if gotErr.Error() != c.Want { - t.Fatalf("unexpected error: got %q, want %q", gotErr, c.Want) - } - } - - t.Run("it panics when the associated function is nil", func(t *testing.T) { - cases := []struct { - Message dogma.Message - Want string - }{ - {CommandA1, `no case function was provided for dogma.Command messages`}, - {EventA1, `no case function was provided for dogma.Event messages`}, - {TimeoutA1, `no case function was provided for dogma.Timeout messages`}, - } - - for _, c := range cases { - func() { - defer func() { - if got := recover(); got != c.Want { - t.Fatalf("unexpected panic: got %q, want %q", got, c.Want) - } - }() - - TryMap[int](c.Message, nil, nil, nil) - }() - } - }) - - t.Run("it panics if the message does not implement any of the more specific interfaces", func(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("expected a panic") - } - }() - - TryMap( - nil, - func(m dogma.Command) (string, error) { t.Fatal("unexpected call to command case"); return "", nil }, - func(m dogma.Event) (string, error) { t.Fatal("unexpected call to event case"); return "", nil }, - func(m dogma.Timeout) (string, error) { t.Fatal("unexpected call to timeout case"); return "", nil }, - ) - }) -} - -func TestSwitchKind(t *testing.T) { - cases := []struct { - Kind Kind - Want string - }{ - {CommandKind, "command"}, - {EventKind, "event"}, - {TimeoutKind, "timeout"}, - } - - for _, c := range cases { - var result string - - SwitchKind( - c.Kind, - func() { result = "command" }, - func() { result = "event" }, - func() { result = "timeout" }, - ) - - if result != c.Want { - t.Fatalf("unexpected result: got %q, want %q", result, c.Want) - } - } - - t.Run("it panics when the associated function is nil", func(t *testing.T) { - cases := []struct { - Kind Kind - Want string - }{ - {CommandKind, `no case function was provided for the "command" kind`}, - {EventKind, `no case function was provided for the "event" kind`}, - {TimeoutKind, `no case function was provided for the "timeout" kind`}, - } - - for _, c := range cases { - func() { - defer func() { - if got := recover(); got != c.Want { - t.Fatalf("unexpected panic: got %q, want %q", got, c.Want) - } - }() - - SwitchKind(c.Kind, nil, nil, nil) - }() - } - }) - - t.Run("it panics when the kind is invalid", func(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("expected a panic") - } - }() - - SwitchKind(Kind(-1), nil, nil, nil) - }) -} - -func TestMapKind(t *testing.T) { - cases := []struct { - Kind Kind - Want string - }{ - {CommandKind, "command"}, - {EventKind, "event"}, - {TimeoutKind, "timeout"}, - } - - for _, c := range cases { - got := MapKind( - c.Kind, - "command", - "event", - "timeout", - ) - - if got != c.Want { - t.Fatalf("unexpected result: got %q, want %q", got, c.Want) - } - } - - t.Run("it panics when the kind is invalid", func(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Fatal("expected a panic") - } - }() - - MapKind(Kind(-1), "command", "event", "timeout") - }) -} diff --git a/message/name.go b/message/name.go deleted file mode 100644 index 7993c928..00000000 --- a/message/name.go +++ /dev/null @@ -1,83 +0,0 @@ -package message - -import ( - "fmt" - "go/types" - "reflect" - - "github.com/dogmatiq/configkit/internal/typename/goreflect" - "github.com/dogmatiq/configkit/internal/typename/gotypes" - "github.com/dogmatiq/dogma" -) - -// Name is the fully-qualified name of a message type. -type Name struct { - n string -} - -// NameOf returns the fully-qualified type name of v. -func NameOf(m dogma.Message) Name { - if m == nil { - panic("message must not be nil") - } - - rt := reflect.TypeOf(m) - n := goreflect.NameOf(rt) - return Name{n} -} - -// NameFor returns the message name for T. -func NameFor[T dogma.Message]() Name { - rt := reflect.TypeFor[T]() - n := goreflect.NameOf(rt) - return Name{n} -} - -// NameFromStaticType returns the fully-qualified type name of t. -func NameFromStaticType(t types.Type) Name { - if t == nil { - panic("type must not be nil") - } - - n := gotypes.NameOf(t) - return Name{n} -} - -// String returns the fully-qualified type name as a string. -func (n Name) String() string { - return n.n -} - -// IsZero returns true if n is the zero-value. -func (n Name) IsZero() bool { - return n.n == "" -} - -// MarshalText returns a UTF-8 representation of the name. -func (n Name) MarshalText() ([]byte, error) { - if n.n == "" { - return nil, fmt.Errorf("can not marshal empty name") - } - - return []byte(n.n), nil -} - -// UnmarshalText unmarshals a name from its UTF-8 representation. -func (n *Name) UnmarshalText(text []byte) error { - if len(text) == 0 { - return fmt.Errorf("can not unmarshal empty name") - } - - n.n = string(text) - return nil -} - -// MarshalBinary returns a binary representation of the name. -func (n Name) MarshalBinary() ([]byte, error) { - return n.MarshalText() -} - -// UnmarshalBinary unmarshals a type from its binary representation. -func (n *Name) UnmarshalBinary(data []byte) error { - return n.UnmarshalText(data) -} diff --git a/message/name_test.go b/message/name_test.go deleted file mode 100644 index 8b8fee8d..00000000 --- a/message/name_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package message_test - -import ( - "go/token" - "go/types" - - . "github.com/dogmatiq/configkit/message" - . "github.com/dogmatiq/enginekit/enginetest/stubs" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("type Name", func() { - Describe("func NameOf()", func() { - It("returns the fully-qualified name", func() { - n := NameOf(CommandA1) - Expect(n.String()).To(Equal("github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA]")) - }) - - It("panics if the message is nil", func() { - Expect(func() { - NameOf(nil) - }).To(Panic()) - }) - }) - - Describe("func NameFor()", func() { - It("returns the name", func() { - na := NameFor[CommandStub[TypeA]]() - nb := NameOf(CommandA1) - Expect(na).To(Equal(nb)) - }) - }) - - Describe("func NameFromStaticType()", func() { - It("returns the fully-qualified name", func() { - pkg := types.NewPackage( - "example.org/somepackage", - "somepackage", - ) - - named := types.NewNamed( - types.NewTypeName( - token.NoPos, - pkg, - "Message", - &types.Struct{}, - ), - nil, - nil, - ) - - n := NameFromStaticType(named) - Expect(n.String()).To(Equal("example.org/somepackage.Message")) - }) - - It("panics if the type is nil", func() { - Expect(func() { - NameFromStaticType(nil) - }).To(Panic()) - }) - }) - - Describe("func MarshalText()", func() { - It("marshals to a textual representation", func() { - n := NameOf(CommandA1) - - buf, err := n.MarshalText() - Expect(err).ShouldNot(HaveOccurred()) - Expect(buf).To(Equal([]byte("github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA]"))) - }) - - It("returns an error if the type is the zero-value", func() { - var n Name - - _, err := n.MarshalText() - Expect(err).Should(HaveOccurred()) - }) - }) - - Describe("func UnmarshalText()", func() { - It("unmarshals from a textual representation", func() { - var n Name - - err := n.UnmarshalText([]byte("github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA]")) - Expect(err).ShouldNot(HaveOccurred()) - Expect(n).To(Equal(NameFor[CommandStub[TypeA]]())) - }) - - It("returns an error if the data is empty", func() { - var n Name - - err := n.UnmarshalText([]byte{}) - Expect(err).Should(HaveOccurred()) - }) - }) - - Describe("func MarshalBinary()", func() { - It("marshals to a textual representation", func() { - n := NameFor[CommandStub[TypeA]]() - - buf, err := n.MarshalBinary() - Expect(err).ShouldNot(HaveOccurred()) - Expect(buf).To(Equal([]byte("github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA]"))) - }) - - It("returns an error if the type is the zero-value", func() { - var n Name - - _, err := n.MarshalBinary() - Expect(err).Should(HaveOccurred()) - }) - }) - - Describe("func UnmarshalBinary()", func() { - It("unmarshals from a textual representation", func() { - var n Name - - err := n.UnmarshalBinary([]byte("github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA]")) - Expect(err).ShouldNot(HaveOccurred()) - Expect(n).To(Equal(NameFor[CommandStub[TypeA]]())) - }) - - It("returns an error if the data is empty", func() { - var n Name - - err := n.UnmarshalBinary([]byte{}) - Expect(err).Should(HaveOccurred()) - }) - }) -}) diff --git a/message/type.go b/message/type.go deleted file mode 100644 index 84b34353..00000000 --- a/message/type.go +++ /dev/null @@ -1,99 +0,0 @@ -package message - -import ( - "reflect" - "strings" - - "github.com/dogmatiq/configkit/internal/typename/goreflect" - "github.com/dogmatiq/dogma" -) - -// Type represents the type of a Dogma message. -type Type struct { - n Name - k Kind - rt reflect.Type -} - -// TypeOf returns the message type of m. -func TypeOf(m dogma.Message) Type { - if m == nil { - panic("message must not be nil") - } - - return TypeFromReflect(reflect.TypeOf(m)) -} - -// TypeFor returns the message type for T. -func TypeFor[T dogma.Message]() Type { - return TypeFromReflect(reflect.TypeFor[T]()) -} - -// TypeFromReflect returns the message type of the given reflect type. -func TypeFromReflect(rt reflect.Type) Type { - return Type{ - Name{goreflect.NameOf(rt)}, - kindFromReflect(rt), - rt, - } -} - -// Name returns the fully-qualified name for the Go type. -// -// It panics if t.IsZero() returns true. -func (t Type) Name() Name { - if t.IsZero() { - panic("can not obtain name of zero-value type") - } - - return t.n -} - -// Kind returns the kind of the message represented by t. -// -// It panics of t does not implement [dogma.Command], [dogma.Event] or -// [dogma.Timeout]. -func (t Type) Kind() Kind { - if t.IsZero() { - panic("can not obtain kind of zero-value type") - } - - return t.k -} - -// ReflectType returns the reflect.Type of the message. -// -// It panics if t.IsZero() returns true. -func (t Type) ReflectType() reflect.Type { - if t.IsZero() { - panic("can not obtain reflect type of zero-value type") - } - - return t.rt -} - -// String returns a human-readable name for the type. -// -// The returned name is not necessarily globally-unique. -func (t Type) String() string { - return typeToString(t.rt) -} - -// IsZero returns true if t is the zero-value. -func (t Type) IsZero() bool { - return t.n.IsZero() -} - -func typeToString(t reflect.Type) string { - if t.Kind() == reflect.Ptr { - return "*" + typeToString(t.Elem()) - } - - str := t.String() - - if pkg := t.PkgPath(); pkg != "" { - str = strings.ReplaceAll(str, pkg+".", "") - } - - return str -} diff --git a/message/type_test.go b/message/type_test.go deleted file mode 100644 index 53227ec9..00000000 --- a/message/type_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package message_test - -import ( - "reflect" - - . "github.com/dogmatiq/configkit/message" - "github.com/dogmatiq/dogma" - . "github.com/dogmatiq/enginekit/enginetest/stubs" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" - . "github.com/onsi/gomega" -) - -var _ = Describe("type Type", func() { - Describe("func TypeOf()", func() { - It("returns values that compare as equal for messages of the same type", func() { - tb := TypeOf(CommandA1) - ta := TypeOf(CommandA1) - - Expect(ta).To(Equal(tb)) - Expect(ta == tb).To(BeTrue()) // we're testing == here specifically, hence not using To(Equal()) - }) - - It("returns values that do not compare as equal for messages of different types", func() { - ta := TypeOf(CommandA1) - tb := TypeOf(EventA1) - - Expect(ta).NotTo(Equal(tb)) - Expect(ta != tb).To(BeTrue()) // we're testing != here specifically, hence not using NotTo(Equal()) - }) - - It("panics if the message is nil", func() { - Expect(func() { - TypeOf(nil) - }).To(Panic()) - }) - }) - - Describe("func TypeFor()", func() { - It("returns the type", func() { - ta := TypeFor[CommandStub[TypeA]]() - tb := TypeOf(CommandA1) - - Expect(ta).To(Equal(tb)) - Expect(ta == tb).To(BeTrue()) // we're testing == here specifically, hence not using To(Equal()) - }) - }) - - Describe("func TypeFromReflect()", func() { - It("returns values that compare as equal for messages of the same type", func() { - tb := TypeFromReflect(reflect.TypeOf(CommandA1)) - ta := TypeFromReflect(reflect.TypeOf(CommandA1)) - - Expect(ta).To(Equal(tb)) - Expect(ta == tb).To(BeTrue()) // we're testing == here specifically, hence not using To(Equal()) - }) - - It("returns values that do not compare as equal for messages of different types", func() { - ta := TypeFromReflect(reflect.TypeOf(CommandA1)) - tb := TypeFromReflect(reflect.TypeOf(EventA1)) - - Expect(ta).NotTo(Equal(tb)) - Expect(ta != tb).To(BeTrue()) // we're testing != here specifically, hence not using NotTo(Equal()) - }) - }) - - Describe("func Name()", func() { - It("returns the fully qualified type name", func() { - mt := TypeOf(CommandA1) - Expect(mt.Name()).To(Equal(NameOf(CommandA1))) - }) - - It("panics if the type is the zero-value", func() { - Expect(func() { - Type{}.Name() - }).To(Panic()) - }) - }) - - Describe("func Kind()", func() { - It("returns the kind of the message", func() { - mt := TypeOf(CommandA1) - Expect(mt.Kind()).To(Equal(CommandKind)) - }) - - It("panics if the type is the zero-value", func() { - Expect(func() { - Type{}.Kind() - }).To(Panic()) - }) - }) - - Describe("func ReflectType()", func() { - It("returns the reflect.Type for the message", func() { - mt := TypeOf(CommandA1) - rt := reflect.TypeOf(CommandA1) - - Expect(mt.ReflectType()).To(BeIdenticalTo(rt)) - }) - - It("panics if the type is the zero-value", func() { - Expect(func() { - Type{}.ReflectType() - }).To(Panic()) - }) - }) - - Describe("func String()", func() { - type NonGenericCommand struct { - CommandStub[TypeA] - } - - DescribeTable( - "it returns the string representation of the type", - func(v dogma.Message, expected string) { - t := TypeOf(v) - Expect(t.String()).To(Equal(expected)) - }, - Entry("generic type", CommandA1, "stubs.CommandStub[TypeA]"), - Entry("pointer to generic type", &CommandA1, "*stubs.CommandStub[TypeA]"), - Entry("non-generic type", NonGenericCommand{}, "message_test.NonGenericCommand"), - Entry("pointer to non-generic type", &NonGenericCommand{}, "*message_test.NonGenericCommand"), - ) - }) -}) diff --git a/process.go b/process.go index 74cfd2bd..d12767d4 100644 --- a/process.go +++ b/process.go @@ -5,8 +5,8 @@ import ( "reflect" "github.com/dogmatiq/configkit/internal/typename/goreflect" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" + "github.com/dogmatiq/enginekit/message" ) // Process is an interface that represents the configuration of a Dogma process diff --git a/process_test.go b/process_test.go index d608b98d..a82fe0ab 100644 --- a/process_test.go +++ b/process_test.go @@ -6,9 +6,9 @@ import ( "reflect" . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" diff --git a/projection.go b/projection.go index 9d579b9b..8679c8b8 100644 --- a/projection.go +++ b/projection.go @@ -6,8 +6,8 @@ import ( "github.com/dogmatiq/configkit/internal/typename/goreflect" "github.com/dogmatiq/configkit/internal/validation" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" + "github.com/dogmatiq/enginekit/message" ) // Projection is an interface that represents the configuration of a Dogma diff --git a/projection_test.go b/projection_test.go index 4d4a2e15..fffecbb6 100644 --- a/projection_test.go +++ b/projection_test.go @@ -6,9 +6,9 @@ import ( "reflect" . "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" "github.com/dogmatiq/dogma" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" diff --git a/static/analysis.go b/static/analysis.go index 822ad012..7726e2f0 100644 --- a/static/analysis.go +++ b/static/analysis.go @@ -8,7 +8,7 @@ import ( "github.com/dogmatiq/configkit" "github.com/dogmatiq/configkit/internal/typename/gotypes" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" "golang.org/x/tools/go/ssa" ) @@ -426,7 +426,7 @@ func addMessagesFromRoutes( // `github.com/dogmatiq/dogma.SchedulesTimeout()` if f, ok := mi.X.(*ssa.Call).Common().Value.(*ssa.Function); ok { messages.Update( - message.NameFromStaticType(f.TypeArgs()[0]), + message.Name(gotypes.NameOf(f.TypeArgs()[0])), func(n message.Name, em *configkit.EntityMessage) { switch { case strings.HasPrefix(f.Name(), "HandlesCommand["): diff --git a/static/app_test.go b/static/app_test.go index 46ae9d9b..c8b01f36 100644 --- a/static/app_test.go +++ b/static/app_test.go @@ -2,9 +2,9 @@ package static_test import ( "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" . "github.com/dogmatiq/configkit/static" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/static/entity.go b/static/entity.go index e33e36c5..8162450d 100644 --- a/static/entity.go +++ b/static/entity.go @@ -4,7 +4,7 @@ import ( "context" "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" ) // application is an implementation of [configkit.Application]. diff --git a/static/handler_conditional_routes_test.go b/static/handler_conditional_routes_test.go index 6df25db6..383ebaa2 100644 --- a/static/handler_conditional_routes_test.go +++ b/static/handler_conditional_routes_test.go @@ -2,9 +2,9 @@ package static_test import ( "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" . "github.com/dogmatiq/configkit/static" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/static/handler_dynamic_routes_test.go b/static/handler_dynamic_routes_test.go index e6eb6ec3..d98d61a4 100644 --- a/static/handler_dynamic_routes_test.go +++ b/static/handler_dynamic_routes_test.go @@ -2,9 +2,9 @@ package static_test import ( "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" . "github.com/dogmatiq/configkit/static" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/static/handler_unregistered_routes_test.go b/static/handler_unregistered_routes_test.go index 82718f8a..110a7372 100644 --- a/static/handler_unregistered_routes_test.go +++ b/static/handler_unregistered_routes_test.go @@ -1,9 +1,9 @@ package static_test import ( - "github.com/dogmatiq/configkit/message" . "github.com/dogmatiq/configkit/static" . "github.com/dogmatiq/enginekit/enginetest/stubs" + "github.com/dogmatiq/enginekit/message" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/string.go b/string.go index 99c62f12..08e84688 100644 --- a/string.go +++ b/string.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" "github.com/dogmatiq/iago/indent" "github.com/dogmatiq/iago/must" ) @@ -98,7 +98,7 @@ func (s *stringer) visitHandler(cfg Handler) error { must.Fprintf( s.w, " %s %s%s\n", - message.MapKind(p.Kind, "executes", "records", "schedules"), + message.MapByKind(p.Kind, "executes", "records", "schedules"), p.Name, p.Kind.Symbol(), ) @@ -163,7 +163,7 @@ func sortNameKinds( return false } - return pi.Name.String() < pj.Name.String() + return pi.Name < pj.Name }, ) diff --git a/visualization/dot/generator.go b/visualization/dot/generator.go index 1e1bfe18..ae82a23a 100644 --- a/visualization/dot/generator.go +++ b/visualization/dot/generator.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" "github.com/emicklei/dot" ) @@ -102,7 +102,7 @@ func (g *generator) addEdges(cfg configkit.Handler, n dot.Node) { // If the edge already exists, its label is expanded to include this message type. func (g *generator) addEdge(src, dst dot.Node, n message.Name) { k := g.kinds[n] - label := n.String() + k.Symbol() + label := string(n) + k.Symbol() index := strings.LastIndex(label, ".") if index != -1 { diff --git a/visualization/dot/style.go b/visualization/dot/style.go index fcece024..dd228906 100644 --- a/visualization/dot/style.go +++ b/visualization/dot/style.go @@ -2,7 +2,7 @@ package dot import ( "github.com/dogmatiq/configkit" - "github.com/dogmatiq/configkit/message" + "github.com/dogmatiq/enginekit/message" "github.com/emicklei/dot" )