forked from adjust/rmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_connection.go
55 lines (43 loc) · 1.16 KB
/
test_connection.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
package rmq
import "fmt"
type TestConnection struct {
queues map[string]*TestQueue
}
func NewTestConnection() TestConnection {
return TestConnection{
queues: map[string]*TestQueue{},
}
}
func (connection TestConnection) OpenQueue(name string) Queue {
if queue, ok := connection.queues[name]; ok {
return queue
}
queue := NewTestQueue(name)
connection.queues[name] = queue
return queue
}
func (connection TestConnection) CollectStats(queueList []string) Stats {
return Stats{}
}
func (connection TestConnection) GetDeliveries(queueName string) []string {
queue, ok := connection.queues[queueName]
if !ok {
return []string{}
}
return queue.LastDeliveries
}
func (connection TestConnection) GetDelivery(queueName string, index int) string {
queue, ok := connection.queues[queueName]
if !ok || index < 0 || index >= len(queue.LastDeliveries) {
return fmt.Sprintf("rmq.TestConnection: delivery not found: %s[%d]", queueName, index)
}
return queue.LastDeliveries[index]
}
func (connection TestConnection) Reset() {
for _, queue := range connection.queues {
queue.Reset()
}
}
func (connection TestConnection) GetOpenQueues() []string {
return []string{}
}