-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmqgo_test.go
108 lines (83 loc) · 1.9 KB
/
rmqgo_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package rmqgo
import (
"reflect"
"testing"
util "github.com/Almazatun/rmqgo/util"
"github.com/rabbitmq/amqp091-go"
)
var mq Rmq
var user, pass, host, port string
var q *amqp091.Queue
func TestInitRmqgo(t *testing.T) {
mq = *New(WithRpc("replay", ExchangeType.Direct()))
if reflect.ValueOf(mq).IsZero() {
t.Fatalf("Rmq not initialized")
}
}
func TestConnection(t *testing.T) {
envs := util.GetENVs()
config := ConnectConfig{User: envs.User, Pass: envs.Pass, Host: envs.Host, Port: envs.Port}
if envs == nil {
t.Fatalf("Rmqgo envs not set")
}
err := mq.Connect(config)
if err != nil {
t.Fatalf(err.Error())
}
}
func TestCreateChannel(t *testing.T) {
ch, err := mq.CreateChannel()
if err != nil {
t.Fatalf("Failed to create channel")
}
mq.channel = ch
}
func TestCreateQueue(t *testing.T) {
args := make(map[string]interface{})
queue, err := mq.CreateQueue(CreateQueueConfig{
Name: "test",
DeleteUnused: false,
Exclusive: false,
NoWait: false,
Durable: true,
Args: &args,
})
if err != nil {
t.Fatalf("Failed to create queue")
}
q = queue
}
func TestCreateExchange(t *testing.T) {
args := make(map[string]interface{})
err := mq.CreateExchange(CreateExchangeConfig{
Name: Exchanges.Direct(),
Type: ExchangeType.Direct(),
Durable: true,
AutoDelete: false,
Internal: false,
NoWait: false,
Args: &args,
})
if err != nil {
t.Fatalf("Failed to create exchange")
}
}
func TestBindExchangeByQueue(t *testing.T) {
args := make(map[string]interface{})
err := mq.BindQueueByExchange(BindQueueByExgConfig{
QueueName: q.Name,
RoutingKey: q.Name,
ExchangeName: Exchanges.Direct(),
NoWait: false,
Args: &args,
})
if err != nil {
t.Fatalf("Failed to bind exchange by queue")
}
}
func TestCloseRmqgo(t *testing.T) {
err := mq.Close()
if err != nil {
t.Fatalf(err.Error())
}
}