diff options
Diffstat (limited to 'app/db/publisher_test.go')
| -rw-r--r-- | app/db/publisher_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/db/publisher_test.go b/app/db/publisher_test.go new file mode 100644 index 0000000..eeb912a --- /dev/null +++ b/app/db/publisher_test.go @@ -0,0 +1,34 @@ +package db + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/xlgmokha/x/pkg/event" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" +) + +func TestWithPublishing(t *testing.T) { + aggregator := event.New[*domain.Sparkle]() + storage := NewRepository[*domain.Sparkle](WithPublishing(aggregator)) + + t.Run("Save", func(t *testing.T) { + t.Run("publishes an event", func(t *testing.T) { + called := false + var payload *domain.Sparkle + + aggregator.SubscribeTo("after.create", func(item *domain.Sparkle) { + called = true + payload = item + }) + + sparkle := &domain.Sparkle{Sparklee: "@tanuki", Reason: "because"} + require.NoError(t, storage.Save(t.Context(), sparkle)) + + require.True(t, called) + require.NotNil(t, payload) + assert.Equal(t, sparkle, payload) + }) + }) +} |
