Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish committed Sep 29, 2024
1 parent 67dfaef commit 21612ec
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
51 changes: 49 additions & 2 deletions broker/sqs/sqs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package sqs_test

import (
"context"
"fmt"
"testing"
"time"

Expand All @@ -25,7 +26,12 @@ import (
func TestEnqueuer(t *testing.T) {
t.Run("NewEnqueuer", func(t *testing.T) {
mock := &mockEnqueue{}
q, err := sqs.NewEnqueuer("test", sqs.WithService(mock))
q, err := sqs.NewEnqueuer("test",
sqs.WithService(mock),
sqs.WithConfig(
swarm.WithLogStdErr(),
),
)
it.Then(t).Should(it.Nil(err))
q.Close()
})
Expand Down Expand Up @@ -55,7 +61,26 @@ func TestEnqueuer(t *testing.T) {
func TestDequeuer(t *testing.T) {
t.Run("NewDequeuer", func(t *testing.T) {
mock := &mockDequeue{}
q, err := sqs.NewDequeuer("test", sqs.WithService(mock))
q, err := sqs.NewDequeuer("test",
sqs.WithService(mock),
sqs.WithBatchSize(10),
sqs.WithConfig(
swarm.WithLogStdErr(),
),
)
it.Then(t).Should(it.Nil(err))
q.Close()
})

t.Run("New", func(t *testing.T) {
mock := &mockDequeue{}
q, err := sqs.New("test",
sqs.WithService(mock),
sqs.WithBatchSize(10),
sqs.WithConfig(
swarm.WithLogStdErr(),
),
)
it.Then(t).Should(it.Nil(err))
q.Close()
})
Expand All @@ -80,6 +105,28 @@ func TestDequeuer(t *testing.T) {
it.Equal(*mock.req.ReceiptHandle, "1"),
)
})

t.Run("Dequeue.Error", func(t *testing.T) {
mock := &mockDequeue{}

q, err := sqs.NewDequeuer("test", sqs.WithService(mock))
it.Then(t).Should(it.Nil(err))

rcv, ack := dequeue.Bytes(q, "test")
go func() {
msg := <-rcv
ack <- msg.Fail(fmt.Errorf("fail"))

time.Sleep(5 * time.Millisecond)
q.Close()
}()

q.Await()

it.Then(t).ShouldNot(
it.Equal(*mock.req.ReceiptHandle, "1"),
)
})
}

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion broker/sqs/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

package sqs

const Version = "broker/sqs/v0.16.1"
const Version = "broker/sqs/v0.20.0"

0 comments on commit 21612ec

Please sign in to comment.