-
Notifications
You must be signed in to change notification settings - Fork 3
/
deliveryInfo_test.go
69 lines (61 loc) · 1.62 KB
/
deliveryInfo_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
package bunnify
import (
"testing"
"github.com/google/uuid"
"github.com/rabbitmq/amqp091-go"
)
func TestGetDeliveryInfo(t *testing.T) {
t.Run("When event gets processed first time", func(t *testing.T) {
// Setup
queueName := uuid.NewString()
exchange := uuid.NewString()
routingKey := uuid.NewString()
// Exercise
info := getDeliveryInfo(queueName, amqp091.Delivery{
Exchange: exchange,
RoutingKey: routingKey,
})
// Assert
if queueName != info.Queue {
t.Fatalf("expected queue %s, got %s", queueName, info.Queue)
}
if exchange != info.Exchange {
t.Fatalf("expected exchange %s, got %s", exchange, info.Exchange)
}
if routingKey != info.RoutingKey {
t.Fatalf("expected routing key %s, got %s", routingKey, info.RoutingKey)
}
})
t.Run("When event has been sent to dead queue", func(t *testing.T) {
// Setup
queueName := uuid.NewString()
exchange := uuid.NewString()
routingKey := uuid.NewString()
// Exercise
info := getDeliveryInfo(queueName, amqp091.Delivery{
Headers: map[string]interface{}{
"x-death": []interface{}{
amqp091.Table{
"queue": queueName,
"exchange": exchange,
"routing-keys": []interface{}{
routingKey,
},
},
},
},
Exchange: "dead-exchange",
RoutingKey: "",
})
// Assert
if queueName != info.Queue {
t.Fatalf("expected queue %s, got %s", queueName, info.Queue)
}
if exchange != info.Exchange {
t.Fatalf("expected exchange %s, got %s", exchange, info.Exchange)
}
if routingKey != info.RoutingKey {
t.Fatalf("expected routing key %s, got %s", routingKey, info.RoutingKey)
}
})
}