-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry_test.go
64 lines (49 loc) · 1.55 KB
/
registry_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
package notificationcenter
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
)
type testPublisher struct{}
func (p *testPublisher) Publish(ctx context.Context, messages ...any) error { return nil }
type testSubscriber struct{}
func (p *testSubscriber) Subscribe(ctx context.Context, receiver Receiver) error { return nil }
func (p *testSubscriber) Listen(ctx context.Context) error { return nil }
func (p *testSubscriber) Close() error { return nil }
type registryTestSuite struct {
suite.Suite
// reg *Registry
}
func (suite *registryTestSuite) SetupSuite() {}
func (suite *registryTestSuite) TearDownSuite() {
suite.NoError(Close())
}
func (suite *registryTestSuite) TestRegister() {
err := Register(
"test1", &testPublisher{},
"test2", &testSubscriber{},
)
suite.NoError(err)
}
func (suite *registryTestSuite) TestNullPublisher() {
suite.Nil(PublisherByName("undefined"))
}
func (suite *registryTestSuite) TestNullSubsciber() {
suite.Nil(SubscriberByName("undefined"))
}
func (suite *registryTestSuite) TestPublish() {
err := Register("test-pub-1", &testPublisher{})
suite.NoError(err)
err = Publish(context.TODO(), "test-pub-1", "hi")
suite.NoError(err)
}
func (suite *registryTestSuite) TestSubscribe() {
err := Register("test-sub-1", &testSubscriber{})
suite.NoError(err)
err = Subscribe(context.TODO(), "test-sub-1",
FuncReceiver(func(msg Message) error { return nil }))
suite.NoError(err)
}
func TestRegister(t *testing.T) {
suite.Run(t, new(registryTestSuite))
}