Skip to content

Commit

Permalink
Use NameOf() and TypeOf() instead of configkit fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Aug 22, 2024
1 parent 9820e05 commit 775531e
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 271 deletions.
40 changes: 20 additions & 20 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ var _ = Describe("func FromApplication()", func() {
Expect(cfg.MessageNames()).To(Equal(
EntityMessageNames{
Produced: message.NameRoles{
cfixtures.MessageCTypeName: message.CommandRole,
cfixtures.MessageETypeName: message.EventRole,
cfixtures.MessageFTypeName: message.EventRole,
cfixtures.MessageTTypeName: message.TimeoutRole,
message.NameFor[fixtures.MessageC](): message.CommandRole,
message.NameFor[fixtures.MessageE](): message.EventRole,
message.NameFor[fixtures.MessageF](): message.EventRole,
message.NameFor[fixtures.MessageT](): message.TimeoutRole,
},
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.CommandRole,
cfixtures.MessageBTypeName: message.EventRole,
cfixtures.MessageCTypeName: message.CommandRole,
cfixtures.MessageDTypeName: message.EventRole,
cfixtures.MessageETypeName: message.EventRole,
cfixtures.MessageTTypeName: message.TimeoutRole,
message.NameFor[fixtures.MessageA](): message.CommandRole,
message.NameFor[fixtures.MessageB](): message.EventRole,
message.NameFor[fixtures.MessageC](): message.CommandRole,
message.NameFor[fixtures.MessageD](): message.EventRole,
message.NameFor[fixtures.MessageE](): message.EventRole,
message.NameFor[fixtures.MessageT](): message.TimeoutRole,
},
},
))
Expand All @@ -133,18 +133,18 @@ var _ = Describe("func FromApplication()", func() {
Expect(cfg.MessageTypes()).To(Equal(
EntityMessageTypes{
Produced: message.TypeRoles{
cfixtures.MessageCType: message.CommandRole,
cfixtures.MessageEType: message.EventRole,
cfixtures.MessageFType: message.EventRole,
cfixtures.MessageTType: message.TimeoutRole,
message.TypeFor[fixtures.MessageC](): message.CommandRole,
message.TypeFor[fixtures.MessageE](): message.EventRole,
message.TypeFor[fixtures.MessageF](): message.EventRole,
message.TypeFor[fixtures.MessageT](): message.TimeoutRole,
},
Consumed: message.TypeRoles{
cfixtures.MessageAType: message.CommandRole,
cfixtures.MessageBType: message.EventRole,
cfixtures.MessageCType: message.CommandRole,
cfixtures.MessageDType: message.EventRole,
cfixtures.MessageEType: message.EventRole,
cfixtures.MessageTType: message.TimeoutRole,
message.TypeFor[fixtures.MessageA](): message.CommandRole,
message.TypeFor[fixtures.MessageB](): message.EventRole,
message.TypeFor[fixtures.MessageC](): message.CommandRole,
message.TypeFor[fixtures.MessageD](): message.EventRole,
message.TypeFor[fixtures.MessageE](): message.EventRole,
message.TypeFor[fixtures.MessageT](): message.TimeoutRole,
},
},
))
Expand Down
119 changes: 59 additions & 60 deletions entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package configkit_test

import (
. "github.com/dogmatiq/configkit"
"github.com/dogmatiq/configkit/fixtures" // can't dot-import due to conflicts
cfixtures "github.com/dogmatiq/configkit/fixtures"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma/fixtures" // can't dot-import due to conflicts
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
Expand All @@ -15,31 +14,31 @@ var _ = Describe("type EntityMessageNames", func() {
It("returns the role of a produced message", func() {
m := EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageATypeName: message.CommandRole,
message.NameFor[fixtures.MessageA](): message.CommandRole,
},
}

r, ok := m.RoleOf(fixtures.MessageATypeName)
r, ok := m.RoleOf(message.NameFor[fixtures.MessageA]())
Expect(ok).To(BeTrue())
Expect(r).To(Equal(message.CommandRole))
})

It("returns the role of a consumed message", func() {
m := EntityMessageNames{
Consumed: message.NameRoles{
fixtures.MessageATypeName: message.CommandRole,
message.NameFor[fixtures.MessageA](): message.CommandRole,
},
}

r, ok := m.RoleOf(fixtures.MessageATypeName)
r, ok := m.RoleOf(message.NameFor[fixtures.MessageA]())
Expect(ok).To(BeTrue())
Expect(r).To(Equal(message.CommandRole))
})

It("returns false if the message is neither produced nor consumed", func() {
m := EntityMessageNames{}

_, ok := m.RoleOf(fixtures.MessageATypeName)
_, ok := m.RoleOf(message.NameFor[fixtures.MessageA]())
Expect(ok).To(BeFalse())
})
})
Expand All @@ -48,17 +47,17 @@ var _ = Describe("type EntityMessageNames", func() {
It("returns the union of the produced and consumed messages", func() {
m := EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageCTypeName: message.CommandRole,
message.NameFor[fixtures.MessageC](): message.CommandRole,
},
Consumed: message.NameRoles{
fixtures.MessageETypeName: message.EventRole,
message.NameFor[fixtures.MessageE](): message.EventRole,
},
}

Expect(m.All()).To(Equal(
message.NameRoles{
fixtures.MessageCTypeName: message.CommandRole,
fixtures.MessageETypeName: message.EventRole,
message.NameFor[fixtures.MessageC](): message.CommandRole,
message.NameFor[fixtures.MessageE](): message.EventRole,
},
))
})
Expand All @@ -68,24 +67,24 @@ var _ = Describe("type EntityMessageNames", func() {
It("returns the set of messages that belong to another application", func() {
m := EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageETypeName: message.EventRole,
fixtures.MessageDTypeName: message.CommandRole, // foreign-consumed command
message.NameFor[fixtures.MessageE](): message.EventRole,
message.NameFor[fixtures.MessageD](): message.CommandRole, // foreign-consumed command
},
Consumed: message.NameRoles{
fixtures.MessageCTypeName: message.CommandRole, // foreign-produced command
fixtures.MessageFTypeName: message.EventRole, // foreign-produced event
fixtures.MessageETypeName: message.EventRole,
message.NameFor[fixtures.MessageC](): message.CommandRole, // foreign-produced command
message.NameFor[fixtures.MessageF](): message.EventRole, // foreign-produced event
message.NameFor[fixtures.MessageE](): message.EventRole,
},
}

Expect(m.Foreign()).To(Equal(
EntityMessageNames{
Produced: message.NameRoles{
cfixtures.MessageDTypeName: message.CommandRole,
message.NameFor[fixtures.MessageD](): message.CommandRole,
},
Consumed: message.NameRoles{
cfixtures.MessageCTypeName: message.CommandRole,
cfixtures.MessageFTypeName: message.EventRole,
message.NameFor[fixtures.MessageC](): message.CommandRole,
message.NameFor[fixtures.MessageF](): message.EventRole,
},
},
))
Expand All @@ -96,19 +95,19 @@ var _ = Describe("type EntityMessageNames", func() {
It("returns true if the sets are equivalent", func() {
a := EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageBTypeName: message.EventRole,
message.NameFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.NameRoles{
fixtures.MessageATypeName: message.CommandRole,
message.NameFor[fixtures.MessageA](): message.CommandRole,
},
}

b := EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageBTypeName: message.EventRole,
message.NameFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.NameRoles{
fixtures.MessageATypeName: message.CommandRole,
message.NameFor[fixtures.MessageA](): message.CommandRole,
},
}

Expand All @@ -120,10 +119,10 @@ var _ = Describe("type EntityMessageNames", func() {
func(b EntityMessageNames) {
a := EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageBTypeName: message.EventRole,
message.NameFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.NameRoles{
fixtures.MessageATypeName: message.CommandRole,
message.NameFor[fixtures.MessageA](): message.CommandRole,
},
}
Expect(a.IsEqual(b)).To(BeFalse())
Expand All @@ -132,23 +131,23 @@ var _ = Describe("type EntityMessageNames", func() {
"produced messages differ",
EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageBTypeName: message.EventRole,
fixtures.MessageCTypeName: message.TimeoutRole, // diff
message.NameFor[fixtures.MessageB](): message.EventRole,
message.NameFor[fixtures.MessageC](): message.TimeoutRole, // diff
},
Consumed: message.NameRoles{
fixtures.MessageATypeName: message.CommandRole,
message.NameFor[fixtures.MessageA](): message.CommandRole,
},
},
),
Entry(
"consumed messages differ",
EntityMessageNames{
Produced: message.NameRoles{
fixtures.MessageBTypeName: message.EventRole,
message.NameFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.NameRoles{
fixtures.MessageATypeName: message.CommandRole,
fixtures.MessageCTypeName: message.TimeoutRole, // diff
message.NameFor[fixtures.MessageA](): message.CommandRole,
message.NameFor[fixtures.MessageC](): message.TimeoutRole, // diff
},
},
),
Expand All @@ -161,31 +160,31 @@ var _ = Describe("type EntityMessageTypes", func() {
It("returns the role of a produced message", func() {
m := EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageAType: message.CommandRole,
message.TypeFor[fixtures.MessageA](): message.CommandRole,
},
}

r, ok := m.RoleOf(fixtures.MessageAType)
r, ok := m.RoleOf(message.TypeFor[fixtures.MessageA]())
Expect(ok).To(BeTrue())
Expect(r).To(Equal(message.CommandRole))
})

It("returns the role of a consumed message", func() {
m := EntityMessageTypes{
Consumed: message.TypeRoles{
fixtures.MessageAType: message.CommandRole,
message.TypeFor[fixtures.MessageA](): message.CommandRole,
},
}

r, ok := m.RoleOf(fixtures.MessageAType)
r, ok := m.RoleOf(message.TypeFor[fixtures.MessageA]())
Expect(ok).To(BeTrue())
Expect(r).To(Equal(message.CommandRole))
})

It("returns false if the message is neither produced nor consumed", func() {
m := EntityMessageTypes{}

_, ok := m.RoleOf(fixtures.MessageAType)
_, ok := m.RoleOf(message.TypeFor[fixtures.MessageA]())
Expect(ok).To(BeFalse())
})
})
Expand All @@ -194,17 +193,17 @@ var _ = Describe("type EntityMessageTypes", func() {
It("returns the union of the produced and consumed messages", func() {
m := EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageCType: message.CommandRole,
message.TypeFor[fixtures.MessageC](): message.CommandRole,
},
Consumed: message.TypeRoles{
fixtures.MessageEType: message.EventRole,
message.TypeFor[fixtures.MessageE](): message.EventRole,
},
}

Expect(m.All()).To(Equal(
message.TypeRoles{
fixtures.MessageCType: message.CommandRole,
fixtures.MessageEType: message.EventRole,
message.TypeFor[fixtures.MessageC](): message.CommandRole,
message.TypeFor[fixtures.MessageE](): message.EventRole,
},
))
})
Expand All @@ -214,24 +213,24 @@ var _ = Describe("type EntityMessageTypes", func() {
It("returns the set of messages that belong to another entity", func() {
m := EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageEType: message.EventRole,
fixtures.MessageDType: message.CommandRole, // foreign-consumed command
message.TypeFor[fixtures.MessageE](): message.EventRole,
message.TypeFor[fixtures.MessageD](): message.CommandRole, // foreign-consumed command
},
Consumed: message.TypeRoles{
fixtures.MessageCType: message.CommandRole, // foreign-produced command
fixtures.MessageFType: message.EventRole, // foreign-produced event
fixtures.MessageEType: message.EventRole,
message.TypeFor[fixtures.MessageC](): message.CommandRole, // foreign-produced command
message.TypeFor[fixtures.MessageF](): message.EventRole, // foreign-produced event
message.TypeFor[fixtures.MessageE](): message.EventRole,
},
}

Expect(m.Foreign()).To(Equal(
EntityMessageTypes{
Produced: message.TypeRoles{
cfixtures.MessageDType: message.CommandRole,
message.TypeFor[fixtures.MessageD](): message.CommandRole,
},
Consumed: message.TypeRoles{
cfixtures.MessageCType: message.CommandRole,
cfixtures.MessageFType: message.EventRole,
message.TypeFor[fixtures.MessageC](): message.CommandRole,
message.TypeFor[fixtures.MessageF](): message.EventRole,
},
},
))
Expand All @@ -242,19 +241,19 @@ var _ = Describe("type EntityMessageTypes", func() {
It("returns true if the sets are equivalent", func() {
a := EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageBType: message.EventRole,
message.TypeFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.TypeRoles{
fixtures.MessageAType: message.CommandRole,
message.TypeFor[fixtures.MessageA](): message.CommandRole,
},
}

b := EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageBType: message.EventRole,
message.TypeFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.TypeRoles{
fixtures.MessageAType: message.CommandRole,
message.TypeFor[fixtures.MessageA](): message.CommandRole,
},
}

Expand All @@ -266,10 +265,10 @@ var _ = Describe("type EntityMessageTypes", func() {
func(b EntityMessageTypes) {
a := EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageBType: message.EventRole,
message.TypeFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.TypeRoles{
fixtures.MessageAType: message.CommandRole,
message.TypeFor[fixtures.MessageA](): message.CommandRole,
},
}
Expect(a.IsEqual(b)).To(BeFalse())
Expand All @@ -278,23 +277,23 @@ var _ = Describe("type EntityMessageTypes", func() {
"produced messages differ",
EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageBType: message.EventRole,
fixtures.MessageCType: message.TimeoutRole, // diff
message.TypeFor[fixtures.MessageB](): message.EventRole,
message.TypeFor[fixtures.MessageC](): message.TimeoutRole, // diff
},
Consumed: message.TypeRoles{
fixtures.MessageAType: message.CommandRole,
message.TypeFor[fixtures.MessageA](): message.CommandRole,
},
},
),
Entry(
"consumed messages differ",
EntityMessageTypes{
Produced: message.TypeRoles{
fixtures.MessageBType: message.EventRole,
message.TypeFor[fixtures.MessageB](): message.EventRole,
},
Consumed: message.TypeRoles{
fixtures.MessageAType: message.CommandRole,
fixtures.MessageCType: message.TimeoutRole, // diff
message.TypeFor[fixtures.MessageA](): message.CommandRole,
message.TypeFor[fixtures.MessageC](): message.TimeoutRole, // diff
},
},
),
Expand Down
Loading

0 comments on commit 775531e

Please sign in to comment.