diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-30 11:03:45 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-30 11:03:45 -0600 |
| commit | c1698f896ff343b1b65e57d3961a78d3bb263b7c (patch) | |
| tree | 3eecd594af67f4849ccea1d8ad758004ccfdec9c /app/db/publisher_test.go | |
| parent | 0626bc0cfffa89b73adc2f9576354e8462270eae (diff) | |
refactor: rename repository types
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) + }) + }) +} |
