From e2d2359ddadeb241fa3bb6c914fe9d058bdd2af2 Mon Sep 17 00:00:00 2001 From: Dmitry Kolesnikov Date: Sun, 29 Sep 2024 00:29:37 +0300 Subject: [PATCH] increase test coverage --- broker/eventbridge/awscdk_test.go | 3 +- broker/eventbridge/eventbridge_test.go | 48 +++++++++++++++++--------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/broker/eventbridge/awscdk_test.go b/broker/eventbridge/awscdk_test.go index 67634af..268c006 100644 --- a/broker/eventbridge/awscdk_test.go +++ b/broker/eventbridge/awscdk_test.go @@ -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", diff --git a/broker/eventbridge/eventbridge_test.go b/broker/eventbridge/eventbridge_test.go index d49cc21..37d8356 100644 --- a/broker/eventbridge/eventbridge_test.go +++ b/broker/eventbridge/eventbridge_test.go @@ -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 { @@ -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()) }() @@ -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() + }) } //------------------------------------------------------------------------------