-
Notifications
You must be signed in to change notification settings - Fork 86
/
amqp_test.go
45 lines (36 loc) · 912 Bytes
/
amqp_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
package worker
import (
"os"
"testing"
amqp "github.com/rabbitmq/amqp091-go"
)
func setupAMQPConn(t *testing.T) (*amqp.Connection, *amqp.Channel) {
if os.Getenv("AMQP_URI") == "" {
t.Skip("skipping amqp test since there is no AMQP_URI")
}
amqpConn, err := amqp.Dial(os.Getenv("AMQP_URI"))
if err != nil {
t.Fatal(err)
}
logChan, err := amqpConn.Channel()
if err != nil {
t.Fatal(err)
}
err = logChan.ExchangeDeclare("reporting", "topic", true, false, false, false, nil)
if err != nil {
return nil, nil
}
_, err = logChan.QueueDeclare("reporting.jobs.logs", true, false, false, false, nil)
if err != nil {
t.Error(err)
}
err = logChan.QueueBind("reporting.jobs.logs", "reporting.jobs.logs", "reporting", false, nil)
if err != nil {
return nil, nil
}
_, err = logChan.QueuePurge("reporting.jobs.logs", false)
if err != nil {
t.Error(err)
}
return amqpConn, logChan
}