Add isQueueAddress() and parseQueueName() helpers to router.go (gt-0q3cg)
Add queue address detection following the same pattern as list address detection. Includes tests in router_test.go. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
52fe464d10
commit
fb5870350c
@@ -60,6 +60,16 @@ func parseListName(address string) string {
|
||||
return strings.TrimPrefix(address, "list:")
|
||||
}
|
||||
|
||||
// isQueueAddress returns true if the address uses queue:name syntax.
|
||||
func isQueueAddress(address string) bool {
|
||||
return strings.HasPrefix(address, "queue:")
|
||||
}
|
||||
|
||||
// parseQueueName extracts the queue name from a queue:name address.
|
||||
func parseQueueName(address string) string {
|
||||
return strings.TrimPrefix(address, "queue:")
|
||||
}
|
||||
|
||||
// expandList returns the recipients for a mailing list.
|
||||
// Returns ErrUnknownList if the list is not found.
|
||||
func (r *Router) expandList(listName string) ([]string, error) {
|
||||
|
||||
@@ -267,6 +267,52 @@ func TestParseListName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsQueueAddress(t *testing.T) {
|
||||
tests := []struct {
|
||||
address string
|
||||
want bool
|
||||
}{
|
||||
{"queue:work", true},
|
||||
{"queue:gastown/polecats", true},
|
||||
{"queue:", true}, // Edge case: empty queue name (will fail on expand)
|
||||
{"mayor/", false},
|
||||
{"gastown/witness", false},
|
||||
{"queuework", false}, // Missing colon
|
||||
{"list:oncall", false},
|
||||
{"", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.address, func(t *testing.T) {
|
||||
got := isQueueAddress(tt.address)
|
||||
if got != tt.want {
|
||||
t.Errorf("isQueueAddress(%q) = %v, want %v", tt.address, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseQueueName(t *testing.T) {
|
||||
tests := []struct {
|
||||
address string
|
||||
want string
|
||||
}{
|
||||
{"queue:work", "work"},
|
||||
{"queue:gastown/polecats", "gastown/polecats"},
|
||||
{"queue:", ""},
|
||||
{"queue:priority-high", "priority-high"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.address, func(t *testing.T) {
|
||||
got := parseQueueName(tt.address)
|
||||
if got != tt.want {
|
||||
t.Errorf("parseQueueName(%q) = %q, want %q", tt.address, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandList(t *testing.T) {
|
||||
// Create temp directory with messaging config
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user