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 28, 2024
1 parent cc88162 commit e2d2359
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
3 changes: 2 additions & 1 deletion broker/eventbridge/awscdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func TestEventBridgeCDK(t *testing.T) {

broker.NewSink(
&eventbridge.SinkProps{
Source: []string{"swarm-example-eventbridge"},
Source: []string{"swarm-example-eventbridge"},
Categories: []string{"category"},
Function: &scud.FunctionGoProps{
SourceCodeModule: "github.com/fogfish/swarm/broker/eventbridge",
SourceCodeLambda: "examples/dequeue/typed",
Expand Down
48 changes: 31 additions & 17 deletions broker/eventbridge/eventbridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ func TestReader(t *testing.T) {
var bag []swarm.Bag
bridge := &bridge{kernel.NewBridge(100 * time.Millisecond)}

t.Run("Success", func(t *testing.T) {
t.Run("New", func(t *testing.T) {
q, err := NewReader("test")
it.Then(t).Should(it.Nil(err))
q.Close()
})

t.Run("Dequeue", func(t *testing.T) {
go func() {
bag, _ = bridge.Ask(context.Background())
for _, m := range bag {
Expand All @@ -163,7 +169,7 @@ func TestReader(t *testing.T) {
)
})

t.Run("Timeout", func(t *testing.T) {
t.Run("Dequeue.Timeout", func(t *testing.T) {
go func() {
bag, _ = bridge.Ask(context.Background())
}()
Expand All @@ -183,24 +189,32 @@ func TestReader(t *testing.T) {
}

func TestWriter(t *testing.T) {
mock := &mockEventBridge{}
t.Run("New", func(t *testing.T) {
q, err := NewWriter("test")
it.Then(t).Should(it.Nil(err))
q.Close()
})

q, err := NewWriter("test", WithService(mock))
it.Then(t).Should(it.Nil(err))
t.Run("Enqueue", func(t *testing.T) {
mock := &mockEventBridge{}

err = q.Emitter.Enq(context.Background(),
swarm.Bag{
Category: "cat",
Object: []byte(`value`),
},
)
it.Then(t).Should(
it.Nil(err),
it.Equal(*mock.val.DetailType, "cat"),
it.Equal(*mock.val.Detail, "value"),
)
q, err := NewWriter("test", WithService(mock))
it.Then(t).Should(it.Nil(err))

q.Close()
err = q.Emitter.Enq(context.Background(),
swarm.Bag{
Category: "cat",
Object: []byte(`value`),
},
)
it.Then(t).Should(
it.Nil(err),
it.Equal(*mock.val.DetailType, "cat"),
it.Equal(*mock.val.Detail, "value"),
)

q.Close()
})
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit e2d2359

Please sign in to comment.