-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_test.go
78 lines (69 loc) · 2.45 KB
/
job_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
74
75
76
77
78
package blockqueue
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/yudhasubki/blockqueue/pkg/core"
"github.com/yudhasubki/blockqueue/pkg/io"
)
func testAddJob(t *testing.T, ctx context.Context, bq *BlockQueue[chan io.ResponseMessages], topic core.Topic, subscriber core.Subscribers, expectErr error) {
err := bq.addJob(ctx, topic, subscriber)
if err != nil {
require.Equal(t, expectErr, err)
} else {
require.NoError(t, err)
}
}
func testDeleteJob(t *testing.T, ctx context.Context, bq *BlockQueue[chan io.ResponseMessages], topic core.Topic, expectErr error) {
err := bq.deleteJob(topic)
if err != nil {
require.Equal(t, expectErr, err)
} else {
require.NoError(t, err)
}
}
func testPublish(t *testing.T, ctx context.Context, bq *BlockQueue[chan io.ResponseMessages], topic core.Topic, request io.Publish, expectErr error) {
err := bq.publish(ctx, topic, request)
if err != nil {
require.Equal(t, expectErr, err)
} else {
require.NoError(t, err)
}
}
func testReadSubscriberMessage(t *testing.T, ctx context.Context, bq *BlockQueue[chan io.ResponseMessages], topic core.Topic, subscriberName string, expectResponse io.ResponseMessages, expectErr error) io.ResponseMessage {
response, err := bq.readSubscriberMessage(ctx, topic, subscriberName)
if err != nil {
require.Equal(t, expectErr, err)
} else {
require.NoError(t, err)
if len(expectResponse) > 0 {
require.EqualValues(t, expectResponse[0].Message, response[0].Message)
return response[0]
}
}
return io.ResponseMessage{}
}
func testAddSubscriber(t *testing.T, ctx context.Context, bq *BlockQueue[chan io.ResponseMessages], topic core.Topic, subscribers core.Subscribers, expectErr error) {
err := bq.addSubscriber(ctx, topic, subscribers)
if err != nil {
require.Equal(t, expectErr, err)
} else {
require.NoError(t, err)
}
}
func testDeleteSubscriber(t *testing.T, ctx context.Context, bq *BlockQueue[chan io.ResponseMessages], topic core.Topic, subscriberName string, expectErr error) {
err := bq.deleteSubscriber(ctx, topic, subscriberName)
if err != nil {
require.Equal(t, expectErr, err)
} else {
require.NoError(t, err)
}
}
func testAckMessage(t *testing.T, ctx context.Context, bq *BlockQueue[chan io.ResponseMessages], topic core.Topic, subscriberName, messageId string, expectErr error) {
err := bq.ackMessage(ctx, topic, subscriberName, messageId)
if err != nil {
require.Equal(t, expectErr, err)
} else {
require.NoError(t, err)
}
}