Skip to content

Commit

Permalink
re add global version test
Browse files Browse the repository at this point in the history
  • Loading branch information
hallgrenx committed Jan 12, 2022
1 parent 389e450 commit aa5a7af
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions eventstore/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func Test(t *testing.T, esFunc eventstoreFunc) {
{"should save and get event concurrently", saveAndGetEventsConcurrently},
{"should return error when no events", getErrWhenNoEvents},
{"should get global event order from save", saveReturnGlobalEventOrder},
{"should set global event on event when saved", setGlobalVersionOnSavedEvents},
}
for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
Expand Down Expand Up @@ -338,3 +339,24 @@ func saveReturnGlobalEventOrder(es eventsourcing.EventStore) error {
}
return nil
}

func setGlobalVersionOnSavedEvents(es eventsourcing.EventStore) error {
aggregateID := AggregateID()
events := testEvents(aggregateID)
err := es.Save(events)
if err != nil {
return err
}
eventsGet, err := es.Get(events[0].AggregateID, events[0].AggregateType, 0)
if err != nil {
return err
}
var g eventsourcing.Version = eventsGet[0].GlobalVersion
for _, e := range eventsGet[1:] {
if e.GlobalVersion < g {
return fmt.Errorf("expected global version to be in sequens exp: %d, was: %d", g, e.GlobalVersion)
}
g = e.GlobalVersion
}
return nil
}

0 comments on commit aa5a7af

Please sign in to comment.