-
Notifications
You must be signed in to change notification settings - Fork 0
/
publisher_test.go
68 lines (50 loc) · 1.42 KB
/
publisher_test.go
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
59
60
61
62
63
64
65
66
67
68
package rcgo
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
)
// This test suite contains all tests that do not require a running server.
type PublisherTestSuite struct {
appName string
suite.Suite
p *Publisher
}
func (s *PublisherTestSuite) SetupSuite() {
url := "amqp://user:password@localhost"
s.appName = "testingPublisherApp"
configs := NewPublisherDefaultConfigs(url)
s.p = NewPublisher(configs, s.appName)
}
func TestPublisherTestSuite(t *testing.T) {
suite.Run(t, new(PublisherTestSuite))
}
func (s *PublisherTestSuite) TestPublisher_New() {
c := NewPublisherDefaultConfigs("")
s.Panics(func() {
NewPublisher(c, s.appName)
})
}
func (s *PublisherTestSuite) TestPublisher_BlockSendMsgsIfStopped() {
c := NewPublisherDefaultConfigs("url")
p := NewPublisher(c, s.appName)
p.Stop()
ctx := context.Background()
err := p.SendCmd(ctx, "tL", "cmd", []byte(""))
s.ErrorIs(err, ErrPublisherStopped)
err = p.PublishEvent(ctx, "event", []byte(""))
s.ErrorIs(err, ErrPublisherStopped)
res, err := p.RequestReply(ctx, "tL", "cmd", []byte(""))
s.ErrorIs(err, ErrPublisherStopped)
s.Equal([]byte{}, res)
ch, err := p.RequestReplyC(ctx, "tL", "cmd", []byte(""))
s.Nil(ch)
s.ErrorIs(err, ErrPublisherStopped)
}
func (s *PublisherTestSuite) TestPublisher_MultipleStops() {
c := NewPublisherDefaultConfigs("url")
p := NewPublisher(c, s.appName)
s.Nil(p.Stop())
s.Nil(p.Stop())
s.Nil(p.Stop())
}