File tree Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,23 @@ import (
77 "github.com/golang-queue/queue/core"
88)
99
10+ // defined in rabbitmq client package.
11+ const (
12+ ExchangeDirect = "direct"
13+ ExchangeFanout = "fanout"
14+ ExchangeTopic = "topic"
15+ ExchangeHeaders = "headers"
16+ )
17+
18+ func isVaildExchange (name string ) bool {
19+ switch name {
20+ case ExchangeDirect , ExchangeFanout , ExchangeTopic , ExchangeHeaders :
21+ return true
22+ default :
23+ return false
24+ }
25+ }
26+
1027// Option for queue system
1128type Option func (* options )
1229
@@ -104,7 +121,7 @@ func newOptions(opts ...Option) options {
104121 subj : "golang-queue" ,
105122 tag : "golang-queue" ,
106123 exchangeName : "test-exchange" ,
107- exchangeType : "direct" ,
124+ exchangeType : ExchangeDirect ,
108125 routingKey : "test-key" ,
109126 logger : queue .NewLogger (),
110127 autoAck : false ,
@@ -119,5 +136,9 @@ func newOptions(opts ...Option) options {
119136 opt (& defaultOpts )
120137 }
121138
139+ if ! isVaildExchange (defaultOpts .exchangeType ) {
140+ defaultOpts .logger .Fatal ("invaild exchange type: " , defaultOpts .exchangeType )
141+ }
142+
122143 return defaultOpts
123144}
Original file line number Diff line number Diff line change 1+ package rabbitmq
2+
3+ import "testing"
4+
5+ func Test_isVaildExchange (t * testing.T ) {
6+ type args struct {
7+ name string
8+ }
9+ tests := []struct {
10+ name string
11+ args args
12+ want bool
13+ }{
14+ {
15+ name : "fanout" ,
16+ args : args {
17+ name : ExchangeFanout ,
18+ },
19+ want : true ,
20+ },
21+ {
22+ name : "invaild exchange type" ,
23+ args : args {
24+ name : "test" ,
25+ },
26+ want : false ,
27+ },
28+ }
29+ for _ , tt := range tests {
30+ t .Run (tt .name , func (t * testing.T ) {
31+ if got := isVaildExchange (tt .args .name ); got != tt .want {
32+ t .Errorf ("isVaildExchange() = %v, want %v" , got , tt .want )
33+ }
34+ })
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments