This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmq_adapter_test.go
125 lines (105 loc) · 3.75 KB
/
mq_adapter_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package rabbitmq
import (
"testing"
"time"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
"github.com/smartystreets/messaging/v2"
"github.com/streadway/amqp"
)
func TestRabbitAdapterFixture(t *testing.T) {
gunit.Run(new(RabbitAdapterFixture), t)
}
type RabbitAdapterFixture struct {
*gunit.Fixture
now time.Time
}
func (this *RabbitAdapterFixture) Setup() {
this.now = utcNow()
}
/////////////////////////////////////////////////////////////////////////////////
func (this *RabbitAdapterFixture) TestAMQPDeliveryConversion() {
upstream := amqp.Delivery{
AppId: "1234",
MessageId: "5678",
Type: "message-type",
ContentType: "content-type",
ContentEncoding: "content-encoding",
Timestamp: this.now,
Body: []byte{1, 2, 3, 4, 5, 6},
DeliveryTag: 8675309,
}
this.So(fromAMQPDelivery(upstream, nil), should.Resemble, messaging.Delivery{
SourceID: 1234,
MessageID: 5678,
MessageType: "message-type",
ContentType: "content-type",
ContentEncoding: "content-encoding",
Timestamp: this.now,
Payload: upstream.Body,
Upstream: upstream,
Receipt: DeliveryReceipt{channel: nil, deliveryTag: upstream.DeliveryTag},
})
}
/////////////////////////////////////////////////////////////////////////////////
func (this *RabbitAdapterFixture) TestAMQPDispatchConversion() {
dispatch := messaging.Dispatch{
SourceID: 1234,
MessageID: 5678,
MessageType: "message-type",
ContentType: "content-type",
ContentEncoding: "content-encoding",
Timestamp: this.now.Add(-time.Second),
Expiration: time.Second,
Durable: true,
Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
}
this.So(toAMQPDispatch(dispatch, this.now), should.Resemble, amqp.Publishing{
AppId: "1234",
MessageId: "5678",
Type: "message-type",
ContentType: "content-type",
ContentEncoding: "content-encoding",
Timestamp: this.now.Add(-time.Second),
Expiration: "1",
DeliveryMode: 2,
Body: dispatch.Payload,
})
}
/////////////////////////////////////////////////////////////////////////////////
func (this *RabbitAdapterFixture) TestAMQPDispatchTimestamp() {
actual := toAMQPDispatch(messaging.Dispatch{}, this.now)
expected := amqp.Publishing{
AppId: "0",
MessageId: "0",
Timestamp: this.now,
DeliveryMode: amqp.Transient,
}
this.So(actual, should.Resemble, expected)
}
/////////////////////////////////////////////////////////////////////////////////
func (this *RabbitAdapterFixture) TestParsingNumericString() {
this.assertParsedValue("1", 1)
this.assertParsedValue("", 0)
this.assertParsedValue("-1", 0)
this.assertParsedValue("-2", 0)
this.assertParsedValue("18446744073709551615", 18446744073709551615)
}
func (this *RabbitAdapterFixture) assertParsedValue(value string, expected uint64) {
this.So(parseUint64(value), should.Equal, expected)
}
/////////////////////////////////////////////////////////////////////////////////
func (this *RabbitAdapterFixture) TestExpirationComputation() {
this.assertExpiration(0, "")
this.assertExpiration(time.Second, "1")
this.assertExpiration(-time.Second, "0")
}
func (this *RabbitAdapterFixture) assertExpiration(expiration time.Duration, expected string) {
this.So(computeExpiration(expiration), should.Equal, expected)
}
/////////////////////////////////////////////////////////////////////////////////
func (this *RabbitAdapterFixture) TestPersistenceComputation() {
this.So(computePersistence(true), should.Equal, amqp.Persistent)
this.So(computePersistence(false), should.Equal, amqp.Transient)
}
/////////////////////////////////////////////////////////////////////////////////