-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabbitevent_test.go
51 lines (46 loc) · 1.11 KB
/
rabbitevent_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
package goschedule
import (
"log"
"os"
"sync"
"testing"
"github.com/streadway/amqp"
)
func TestRabbitEvent(t *testing.T) {
conn, err := amqp.Dial(os.Getenv("RABBITMQ_URL"))
if err != nil {
log.Fatalf("Failed to connect to rabbitmq: %s", err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
log.Fatalf("Failed to open a channel: %s", err)
}
defer ch.Close()
q, err := ch.QueueDeclare(
"hello", // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
log.Fatalf("Failed to declare a queue: %s", err)
}
body := []byte("Hello World!")
exchange := ""
routingKey := q.Name
mandatory := false
immediate := false
contentType := "text/plain"
var wg sync.WaitGroup
rabbitEvent := newRabbitMQEvent(ch, exchange, routingKey, mandatory, immediate, contentType, body, "example1")
wg.Add(1)
go rabbitEvent.publishEvent(&wg)
wg.Wait()
eventInfo := rabbitEvent.GetRabbitEventInfo()
if eventInfo.LatestPublishStatus != "success" {
t.Error("Got: ", eventInfo.LatestPublishStatus, " Wanted: success")
}
}