Newer
Older
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
package emissionqueue_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"orus.io/orus-io/go-orusapi/database"
"orus.io/orus-io/go-orusapi/testutils"
"orus.io/orus-io/go-orusapi/xbus/emissionqueue"
"orus.io/orus-io/go-orusapi/xbus/emissionqueue/migration"
)
func TestEmissionQueue(t *testing.T) {
log := testutils.GetLogger(t)
db := database.GetTestDB(context.TODO(), t, migration.Source)
defer db.Close()
queue := emissionqueue.NewEmissionQueue()
assert.NotNil(t, queue)
sqlHelper := database.NewSQLHelper(context.Background(), db, log)
require.NoError(t, queue.AddMessage(&sqlHelper, emissionqueue.NewMessage("AddMessage", "test", []byte("abcde"))))
require.NoError(t, queue.Add(&sqlHelper, "Add", "test", "fghij"))
var messages []emissionqueue.Message
require.NoError(t,
database.Select(db, &messages,
database.SQ.
Select("id", "related_to", "msgtype", "content").
From(emissionqueue.TableName).
OrderBy("id"),
&log))
var relatedTo []string
require.Len(t, messages, 2)
if assert.NoError(t, messages[0].RelatedTo.AssignTo(&relatedTo)) {
assert.Equal(t, []string{"AddMessage"}, relatedTo)
}
assert.Equal(t, "test", messages[0].MsgType)
assert.Equal(t, "abcde", string(messages[0].Content))
if assert.NoError(t, messages[1].RelatedTo.AssignTo(&relatedTo)) {
assert.Equal(t, []string{"Add"}, relatedTo)
}
assert.Equal(t, "test", messages[1].MsgType)
assert.Equal(t, `"fghij"`, string(messages[1].Content))
}