Skip to content

Commit

Permalink
fix: improve courier test signature
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Jan 13, 2022
1 parent d518958 commit 721b886
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions courier/test/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type PersisterWrapper interface {
courier.Persister
}

type NetworkWrapper func() (uuid.UUID, PersisterWrapper)
type NetworkWrapper func(t *testing.T, ctx context.Context) (uuid.UUID, PersisterWrapper)

func TestPersister(ctx context.Context, newNetworkUnlessExisting NetworkWrapper, newNetwork NetworkWrapper) func(t *testing.T) {
return func(t *testing.T) {
nid, p := newNetworkUnlessExisting()
nid, p := newNetworkUnlessExisting(t, ctx)

t.Run("case=no messages in queue", func(t *testing.T) {
m, err := p.NextMessages(ctx, 10)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestPersister(ctx context.Context, newNetworkUnlessExisting NetworkWrapper,
})

t.Run("can not get on another network", func(t *testing.T) {
_, p := newNetwork()
_, p := newNetwork(t, ctx)

_, err := p.LatestQueuedMessage(ctx)
require.ErrorIs(t, err, courier.ErrQueueEmpty)
Expand All @@ -126,7 +126,7 @@ func TestPersister(ctx context.Context, newNetworkUnlessExisting NetworkWrapper,
})

t.Run("can not update on another network", func(t *testing.T) {
_, p := newNetwork()
_, p := newNetwork(t, ctx)
err := p.SetMessageStatus(ctx, id, courier.MessageStatusProcessing)
require.ErrorIs(t, err, sqlcon.ErrNoRows)
})
Expand Down
2 changes: 1 addition & 1 deletion persistence/sql/persister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestPersister(t *testing.T) {
})
t.Run("contract=courier.TestPersister", func(t *testing.T) {
pop.SetLogger(pl(t))
upsert, insert := sqltesthelpers.DefaultNetworkWrapper(t, ctx, p)
upsert, insert := sqltesthelpers.DefaultNetworkWrapper(p)
courier.TestPersister(ctx, upsert, insert)(t)
})
t.Run("contract=verification.TestPersister", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions persistence/sql/testhelpers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/ory/kratos/persistence"
)

func DefaultNetworkWrapper(t *testing.T, ctx context.Context, p persistence.Persister) (courier.NetworkWrapper, courier.NetworkWrapper) {
return func() (db.UUID, courier.PersisterWrapper) {
func DefaultNetworkWrapper(p persistence.Persister) (courier.NetworkWrapper, courier.NetworkWrapper) {
return func(t *testing.T, ctx context.Context) (db.UUID, courier.PersisterWrapper) {
return testhelpers.NewNetworkUnlessExisting(t, ctx, p)
}, func() (db.UUID, courier.PersisterWrapper) {
}, func(t *testing.T, ctx context.Context) (db.UUID, courier.PersisterWrapper) {
return testhelpers.NewNetwork(t, ctx, p)
}
}

0 comments on commit 721b886

Please sign in to comment.