Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 387532c

Browse files
authored
Merge pull request #1 from vimeda/dont-require-uuid
Remove UUID constraint
2 parents 4896794 + 0554bea commit 387532c

File tree

4 files changed

+3
-81
lines changed

4 files changed

+3
-81
lines changed

aggregate/aggregate.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
package aggregate
22

33
import (
4-
"errors"
54
"time"
65

76
"github.com/google/uuid"
87
"github.com/hellofresh/goengine"
98
"github.com/hellofresh/goengine/metadata"
109
)
1110

12-
// ErrInvalidID occurs when a string is not a valid ID
13-
var ErrInvalidID = errors.New("goengine: an aggregate.ID must be a valid UUID")
14-
1511
type (
16-
// ID an UUID for a aggregate.Root instance
12+
// ID for a aggregate.Root instance
1713
ID string
1814

1915
// Root is a interface that a AggregateRoot must implement
@@ -49,16 +45,6 @@ func GenerateID() ID {
4945
return ID(uuid.New().String())
5046
}
5147

52-
// IDFromString creates a ID from a string
53-
func IDFromString(str string) (ID, error) {
54-
id, err := uuid.Parse(str)
55-
if err != nil {
56-
return "", ErrInvalidID
57-
}
58-
59-
return ID(id.String()), nil
60-
}
61-
6248
// RecordChange record the given event onto the aggregate.Root by wrapping it in an aggregate.Changed
6349
func RecordChange(aggregateRoot Root, event interface{}) error {
6450
aggregateID := aggregateRoot.AggregateID()

aggregate/aggregate_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,66 +24,6 @@ func TestGenerateID(t *testing.T) {
2424
asserts.NotEqual(firstID, secondID, "Expected GenerateID() to return a different ID")
2525
}
2626

27-
func TestIDFromString(t *testing.T) {
28-
t.Run("valid uuid", func(t *testing.T) {
29-
type uuidTestCase struct {
30-
title string
31-
input string
32-
output aggregate.ID
33-
}
34-
35-
testCases := []uuidTestCase{
36-
{
37-
"UUID",
38-
"bf27f3c1-5fd6-4997-896a-63774ebd9ab0",
39-
aggregate.ID("bf27f3c1-5fd6-4997-896a-63774ebd9ab0"),
40-
},
41-
{
42-
"UUID with prefix",
43-
"urn:uuid:f4ec75db-c0b0-4b00-a04f-a0d9ed18e9fb",
44-
aggregate.ID("f4ec75db-c0b0-4b00-a04f-a0d9ed18e9fb"),
45-
},
46-
}
47-
48-
for _, testCase := range testCases {
49-
t.Run(testCase.title, func(t *testing.T) {
50-
id, err := aggregate.IDFromString(testCase.input)
51-
52-
assert.NoError(t, err)
53-
assert.Equal(t, testCase.output, id)
54-
})
55-
}
56-
})
57-
58-
t.Run("invalid uuid", func(t *testing.T) {
59-
type invalidTestCase struct {
60-
title string
61-
input string
62-
}
63-
64-
testCases := []invalidTestCase{
65-
{
66-
"some string",
67-
"some string",
68-
},
69-
{
70-
"UUID with missing minuses",
71-
"f4ec75dbc0b04b00a04fa0d9ed18e9fb",
72-
},
73-
}
74-
75-
for _, testCase := range testCases {
76-
t.Run(testCase.title, func(t *testing.T) {
77-
id, err := aggregate.IDFromString(testCase.input)
78-
79-
asserts := assert.New(t)
80-
asserts.Equal(aggregate.ErrInvalidID, err)
81-
asserts.Equal(aggregate.ID(""), id)
82-
})
83-
}
84-
})
85-
}
86-
8727
func TestRecordChange(t *testing.T) {
8828
t.Run("A change is recorded", func(t *testing.T) {
8929
asserts := assert.New(t)

strategy/json/sql/message_factory_aggregate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func aggregateIDFromMetadata(meta metadata.Metadata) (aggregate.ID, error) {
120120
return "", &InvalidMetadataValueTypeError{key: aggregate.IDKey, value: val, expected: "string"}
121121
}
122122

123-
return aggregate.IDFromString(str)
123+
return aggregate.ID(str), nil
124124
}
125125

126126
func aggregateVersionFromMetadata(meta metadata.Metadata) (uint, error) {

test/projector_aggregate_integration_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,10 @@ func (s *aggregateProjectorTestSuite) assertAggregateProjectionStates(expectedPr
357357
}
358358

359359
func createAggregateIds(ids []string) []aggregate.ID {
360-
var err error
361360
res := make([]aggregate.ID, len(ids))
362361

363362
for i, id := range ids {
364-
res[i], err = aggregate.IDFromString(id)
365-
if err != nil {
366-
panic(err)
367-
}
363+
res[i] = aggregate.ID(id)
368364
}
369365

370366
return res

0 commit comments

Comments
 (0)