-
Notifications
You must be signed in to change notification settings - Fork 5
/
redis_transport_test.go
58 lines (48 loc) · 1.08 KB
/
redis_transport_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
package gosumer
import (
"context"
"testing"
"time"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert"
)
func TestRedisConnect(t *testing.T) {
transport := Redis{
Host: "localhost",
Port: 6379,
Channel: "channel_name",
}
err := transport.connect()
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
}
func TestRedisListen(t *testing.T) {
transport := Redis{
Host: "localhost",
Port: 6379,
User: "",
Password: "",
Channel: "channel_1",
DB: 0,
}
go func() {
err := transport.listen(processMessage, Message{}, 0)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
}()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
time.Sleep(1 * time.Second)
ctx := context.Background()
body := `{"id": 1, "name": "John Doe"}`
res := rdb.Publish(ctx, "channel_1", body)
if res.Err() != nil {
t.Errorf("Expected no error, got %v", res.Err())
}
time.Sleep(1 * time.Second)
assert.True(t, processMessageCalled, "Expected processMessage to be called")
processMessageCalled = false
}