-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublisher_test.go
More file actions
58 lines (53 loc) · 1.59 KB
/
Copy pathpublisher_test.go
File metadata and controls
58 lines (53 loc) · 1.59 KB
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
package rabbitmq
import (
"errors"
"testing"
"time"
)
func TestSnapDelay_Ladder(t *testing.T) {
tests := []struct {
delay time.Duration
want time.Duration
}{
{50 * time.Millisecond, 1 * time.Second},
{1 * time.Second, 1 * time.Second},
{2 * time.Second, 5 * time.Second},
{45 * time.Second, 1 * time.Minute},
{1 * time.Hour, 1 * time.Hour},
}
for _, tt := range tests {
got, err := snapDelay(tt.delay)
if err != nil {
t.Errorf("snapDelay(%s) unexpected error: %v", tt.delay, err)
continue
}
if got != tt.want {
t.Errorf("snapDelay(%s) = %s, want %s", tt.delay, got, tt.want)
}
}
if _, err := snapDelay(2 * time.Hour); !errors.Is(err, ErrDelayTooLong) {
t.Errorf("snapDelay(2h) error = %v, want ErrDelayTooLong", err)
}
}
func TestDelayQueueName_Deterministic(t *testing.T) {
if a, b := delayQueueName("ex", "key", time.Second), delayQueueName("ex", "key", time.Second); a != b {
t.Errorf("delayQueueName not deterministic: %q != %q", a, b)
}
// Different destinations and delays must not collide.
if delayQueueName("ex", "key", time.Second) == delayQueueName("ex", "key2", time.Second) {
t.Error("delayQueueName collided on different routing key")
}
if delayQueueName("ex", "key", time.Second) == delayQueueName("ex", "key", 5*time.Second) {
t.Error("delayQueueName collided on different delay")
}
}
func TestDelayLadder_ReturnsCopy(t *testing.T) {
l := DelayLadder()
if len(l) == 0 {
t.Fatal("DelayLadder returned empty")
}
l[0] = 999 * time.Hour
if DelayLadder()[0] == 999*time.Hour {
t.Error("DelayLadder exposed its backing array; mutation leaked")
}
}