Skip to content

Commit c16a0ff

Browse files
authored
Panic for unregistered queues (#4)
* Panic for unregistered queues * Test that getting an unregistered queue panics.
1 parent b319b3c commit c16a0ff

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

queue.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,9 @@ func (q *queues) add(queue Queue) {
125125
func (q *queues) get(name string) Queue {
126126
q.RLock()
127127
defer q.RUnlock()
128-
return q.registry[name]
128+
val, ok := q.registry[name]
129+
if !ok {
130+
panic(fmt.Sprintf("queue '%s' not registered, ensure all queues are registered before calling Client.Start()", name))
131+
}
132+
return val
129133
}

queue_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package backlite
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57
"testing"
68
)
79

@@ -14,3 +16,19 @@ func TestQueue_CannotDecode(t *testing.T) {
1416
t.Error("Process should have failed")
1517
}
1618
}
19+
20+
func TestQueues_GetUnregisteredQueuePanics(t *testing.T) {
21+
s := &queues{}
22+
23+
defer func() {
24+
if r := recover(); r == nil {
25+
t.Errorf("Should be panicking, but it didn't")
26+
} else {
27+
if msg, ok := r.(string); !ok || !strings.Contains(msg, fmt.Sprintf("queue '%s' not registered", testTask{}.Config().Name)) {
28+
t.Errorf("Unexpected panic value: %v", r)
29+
}
30+
}
31+
}()
32+
33+
s.get(testTask{}.Config().Name)
34+
}

0 commit comments

Comments
 (0)