github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/data/queue/consumer/nsq_test.go (about) 1 package consumer 2 3 import ( 4 "github.com/angenalZZZ/gofunc/data/queue/message" 5 "github.com/angenalZZZ/gofunc/data/queue/nsq" 6 . "github.com/smartystreets/goconvey/convey" 7 "testing" 8 ) 9 10 func testNSQMsgHandle(m *message.NsqMessage) error { 11 println(m.Message) 12 return nil // handle message finish 13 } 14 15 func TestNSQRegister(t *testing.T) { 16 Convey("Given topic, channel, maxInflight and message handler method", t, func() { 17 Convey("It should not produce any error", func() { 18 c := NewNsqConsumer() 19 err := c.Register(nsq.TestTopic, nsq.TestChannel, 2, testNSQMsgHandle) 20 So(err, ShouldEqual, nil) 21 }) 22 }) 23 24 //Convey("Given wrong topic, channel", t, func() { 25 // Convey("It should produce an error", func() { 26 // c := NewNsqConsumer() 27 // err := c.Register("", "", maxInFlight, testNSQMsgHandle) 28 // So(err, ShouldNotEqual, nil) 29 // }) 30 //}) 31 } 32 33 func TestNSQMessageHandler(t *testing.T) { 34 Convey("Given topic, channel, maxInflight and message handler method", t, func() { 35 Convey("It should not produce any error", func() { 36 c := NewNsqConsumer() 37 err := c.Register(nsq.TestTopic, nsq.TestChannel, 2, testNSQMsgHandle) 38 So(err, ShouldEqual, nil) 39 err = c.Connect(nsq.NSQdTCPAddr) 40 So(err, ShouldEqual, nil) 41 c.Stop() 42 }) 43 }) 44 } 45 46 func TestNSQConnectLookupD(t *testing.T) { 47 Convey("Given lookupD address", t, func() { 48 Convey("It should not produce any error", func() { 49 c := NewNsqConsumer() 50 err := c.ConnectLookupD(nsq.LOOKUPdHTTPAddr) 51 So(err, ShouldEqual, nil) 52 }) 53 }) 54 55 //Convey("Given wrong lookupD address", t, func() { 56 // Convey("It should produce an error", func() { 57 // c := NewNsqConsumer() 58 // err := c.ConnectLookupD("127.0.0.1") 59 // So(err, ShouldNotEqual, nil) 60 // }) 61 //}) 62 } 63 64 func TestNSQConnect(t *testing.T) { 65 Convey("Given nsqD address", t, func() { 66 Convey("It should not produce any error", func() { 67 c := NewNsqConsumer() 68 err := c.Connect(nsq.NSQdTCPAddr) 69 So(err, ShouldEqual, nil) 70 }) 71 }) 72 73 //Convey("Given wrong nsqD address", t, func() { 74 // Convey("It should produce an error", func() { 75 // c := NewNsqConsumer() 76 // err := c.Connect("127.0.0.1") 77 // So(err, ShouldNotEqual, nil) 78 // }) 79 //}) 80 }