-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventddb_test.go
73 lines (62 loc) · 1.37 KB
/
eventddb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Copyright (C) 2021 - 2024 Dmitry Kolesnikov
//
// This file may be modified and distributed under the terms
// of the Apache License Version 2.0. See the LICENSE file for details.
// https://github.com/fogfish/swarm
//
package eventddb
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/fogfish/it/v2"
"github.com/fogfish/swarm"
"github.com/fogfish/swarm/kernel"
)
func TestReader(t *testing.T) {
var bag []swarm.Bag
bridge := &bridge{kernel.NewBridge(100 * time.Millisecond)}
t.Run("NewReader", func(t *testing.T) {
q, err := NewReader(
WithConfig(
swarm.WithLogStdErr(),
),
)
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 {
bridge.Ack(context.Background(), m.Digest)
}
}()
err := bridge.run(
DynamoDBEvent{
Records: []json.RawMessage{[]byte(`{"sut":"test"}`)},
},
)
it.Then(t).Should(
it.Nil(err),
it.Equal(len(bag), 1),
it.Equal(bag[0].Category, Category),
it.Equiv(bag[0].Object, []byte(`{"sut":"test"}`)),
)
})
t.Run("Dequeue.Timeout", func(t *testing.T) {
go func() {
bag, _ = bridge.Ask(context.Background())
}()
err := bridge.run(
DynamoDBEvent{
Records: []json.RawMessage{[]byte(`{"sut":"test"}`)},
},
)
it.Then(t).ShouldNot(
it.Nil(err),
)
})
}