-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aggregate.go): add Comparable interface and TransitionWithEqual …
…function for custom event data comparison refactor(aggregate.go): modify TransitionTest struct and related functions to use custom isEqual function for event data comparison test(aggregate_test.go): add tests for new TransitionWithEqual function and Comparable interface usage
- Loading branch information
Showing
2 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package gtest_test | ||
|
||
import ( | ||
"slices" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/modernice/goes/aggregate" | ||
"github.com/modernice/goes/exp/gtest" | ||
) | ||
|
||
func TestTransition(t *testing.T) { | ||
type data struct { | ||
Foo string | ||
Bar int | ||
} | ||
|
||
foo := aggregate.New("foo", uuid.New()) | ||
|
||
d := data{Foo: "foo", Bar: 42} | ||
aggregate.Next(foo, "foo", d) | ||
|
||
gtest.Transition("foo", d).Run(t, foo) | ||
} | ||
|
||
type comparableData struct { | ||
Foo string | ||
Bar int | ||
Baz []bool | ||
} | ||
|
||
// Equal checks if two instances of comparableData are equivalent by comparing | ||
// their Foo, Bar, and Baz fields. It returns true if all corresponding fields | ||
// between the two instances are equal, false otherwise. | ||
func (d comparableData) Equal(d2 comparableData) bool { | ||
return d.Foo == d2.Foo && d.Bar == d2.Bar && slices.Equal(d.Baz, d2.Baz) | ||
} | ||
|
||
func TestTransitionWithEqual(t *testing.T) { | ||
foo := aggregate.New("foo", uuid.New()) | ||
|
||
d := comparableData{Foo: "foo", Bar: 42, Baz: []bool{true, false}} | ||
aggregate.Next(foo, "foo", d) | ||
|
||
gtest.TransitionWithEqual("foo", d).Run(t, foo) | ||
} |