@@ -22,6 +22,7 @@ import (
2222 "github.com/stretchr/testify/assert"
2323 "github.com/stretchr/testify/require"
2424 "github.com/uber-go/tally/v4"
25+ "github.com/uber/submitqueue/core/consumer"
2526 "github.com/uber/submitqueue/entity"
2627 "github.com/uber/submitqueue/entity/queue"
2728 countermock "github.com/uber/submitqueue/extension/counter/mock"
@@ -32,11 +33,29 @@ import (
3233 "go.uber.org/zap"
3334)
3435
35- // noopPublisher returns a mock publisher that succeeds silently.
36- func noopPublisher (ctrl * gomock.Controller ) * queuemock.MockPublisher {
36+ // newTestRegistry builds a single-entry TopicRegistry for TopicKeyStart wired
37+ // to a mock Queue/Publisher and returns both the registry and the publisher
38+ // mock so callers can set EXPECT() on the publisher.
39+ func newTestRegistry (t * testing.T , ctrl * gomock.Controller ) (consumer.TopicRegistry , * queuemock.MockPublisher ) {
40+ t .Helper ()
3741 pub := queuemock .NewMockPublisher (ctrl )
42+ q := queuemock .NewMockQueue (ctrl )
43+ q .EXPECT ().Publisher ().Return (pub ).AnyTimes ()
44+
45+ registry , err := consumer .NewTopicRegistry ([]consumer.TopicConfig {
46+ {Key : consumer .TopicKeyStart , Name : "start" , Queue : q },
47+ })
48+ require .NoError (t , err )
49+ return registry , pub
50+ }
51+
52+ // newTestRegistryWithNoopPublisher returns a registry whose publisher silently
53+ // accepts any Publish call. Use for tests that don't care about publish behavior.
54+ func newTestRegistryWithNoopPublisher (t * testing.T , ctrl * gomock.Controller ) consumer.TopicRegistry {
55+ t .Helper ()
56+ registry , pub := newTestRegistry (t , ctrl )
3857 pub .EXPECT ().Publish (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
39- return pub
58+ return registry
4059}
4160
4261// noopRequestLogStore returns a mock RequestLogStore that succeeds silently.
@@ -50,7 +69,7 @@ func TestNewLandController(t *testing.T) {
5069 ctrl := gomock .NewController (t )
5170
5271 cnt := countermock .NewMockCounter (ctrl )
53- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopPublisher (ctrl ), noopRequestLogStore ( ctrl ), "request" )
72+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), newTestRegistryWithNoopPublisher ( t , ctrl ) )
5473 require .NotNil (t , controller )
5574}
5675
@@ -59,7 +78,7 @@ func TestLand_ReturnsSqid(t *testing.T) {
5978
6079 cnt := countermock .NewMockCounter (ctrl )
6180 cnt .EXPECT ().Next (gomock .Any (), gomock .Any ()).Return (int64 (1 ), nil )
62- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopPublisher (ctrl ), noopRequestLogStore ( ctrl ), "request" )
81+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), newTestRegistryWithNoopPublisher ( t , ctrl ) )
6382 ctx := context .Background ()
6483
6584 req := & pb.LandRequest {
@@ -77,7 +96,7 @@ func TestLand_ReturnsErrorOnCounterFailure(t *testing.T) {
7796
7897 cnt := countermock .NewMockCounter (ctrl )
7998 cnt .EXPECT ().Next (gomock .Any (), gomock .Any ()).Return (int64 (0 ), fmt .Errorf ("counter unavailable" ))
80- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopPublisher (ctrl ), noopRequestLogStore ( ctrl ), "request" )
99+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), newTestRegistryWithNoopPublisher ( t , ctrl ) )
81100 ctx := context .Background ()
82101
83102 req := & pb.LandRequest {
@@ -101,7 +120,7 @@ func TestLand_CounterDomainIncludesQueue(t *testing.T) {
101120 return 1 , nil
102121 },
103122 )
104- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopPublisher (ctrl ), noopRequestLogStore ( ctrl ), "request" )
123+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), newTestRegistryWithNoopPublisher ( t , ctrl ) )
105124 ctx := context .Background ()
106125
107126 req := & pb.LandRequest {
@@ -118,7 +137,7 @@ func TestLand_ReturnsErrorOnEmptyQueue(t *testing.T) {
118137 ctrl := gomock .NewController (t )
119138
120139 cnt := countermock .NewMockCounter (ctrl )
121- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopPublisher (ctrl ), noopRequestLogStore ( ctrl ), "request" )
140+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), newTestRegistryWithNoopPublisher ( t , ctrl ) )
122141 ctx := context .Background ()
123142
124143 req := & pb.LandRequest {
@@ -135,7 +154,7 @@ func TestLand_ReturnsErrorOnEmptyChangeUri(t *testing.T) {
135154 ctrl := gomock .NewController (t )
136155
137156 cnt := countermock .NewMockCounter (ctrl )
138- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopPublisher (ctrl ), noopRequestLogStore ( ctrl ), "request" )
157+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), newTestRegistryWithNoopPublisher ( t , ctrl ) )
139158 ctx := context .Background ()
140159
141160 req := & pb.LandRequest {
@@ -152,7 +171,7 @@ func TestLand_ReturnsErrorOnNilChange(t *testing.T) {
152171 ctrl := gomock .NewController (t )
153172
154173 cnt := countermock .NewMockCounter (ctrl )
155- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopPublisher (ctrl ), noopRequestLogStore ( ctrl ), "request" )
174+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), newTestRegistryWithNoopPublisher ( t , ctrl ) )
156175 ctx := context .Background ()
157176
158177 req := & pb.LandRequest {
@@ -173,7 +192,8 @@ func TestLand_PublishesToQueue(t *testing.T) {
173192
174193 cnt := countermock .NewMockCounter (ctrl )
175194 cnt .EXPECT ().Next (gomock .Any (), gomock .Any ()).Return (int64 (123 ), nil )
176- publisher := queuemock .NewMockPublisher (ctrl )
195+
196+ registry , publisher := newTestRegistry (t , ctrl )
177197 publisher .EXPECT ().Publish (gomock .Any (), gomock .Any (), gomock .Any ()).DoAndReturn (
178198 func (ctx context.Context , topic string , msg queue.Message ) error {
179199 publishedTopic = topic
@@ -182,7 +202,7 @@ func TestLand_PublishesToQueue(t *testing.T) {
182202 },
183203 )
184204
185- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , publisher , noopRequestLogStore (ctrl ), "request" )
205+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), registry )
186206 ctx := context .Background ()
187207
188208 req := & pb.LandRequest {
@@ -195,8 +215,8 @@ func TestLand_PublishesToQueue(t *testing.T) {
195215 require .NoError (t , err )
196216 assert .Equal (t , "test-queue/123" , resp .Sqid )
197217
198- // Verify message was published
199- assert .Equal (t , "request " , publishedTopic )
218+ // Verify message was published to the topic registered under TopicKeyStart
219+ assert .Equal (t , "start " , publishedTopic )
200220 assert .Equal (t , "test-queue/123" , publishedMessage .ID )
201221 assert .Equal (t , "test-queue" , publishedMessage .PartitionKey )
202222
@@ -214,10 +234,11 @@ func TestLand_ContinuesWhenPublishFails(t *testing.T) {
214234
215235 cnt := countermock .NewMockCounter (ctrl )
216236 cnt .EXPECT ().Next (gomock .Any (), gomock .Any ()).Return (int64 (999 ), nil )
217- publisher := queuemock .NewMockPublisher (ctrl )
237+
238+ registry , publisher := newTestRegistry (t , ctrl )
218239 publisher .EXPECT ().Publish (gomock .Any (), gomock .Any (), gomock .Any ()).Return (fmt .Errorf ("queue unavailable" ))
219240
220- controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , publisher , noopRequestLogStore (ctrl ), "request" )
241+ controller := NewLandController (zap .NewNop ().Sugar (), tally .NoopScope , cnt , noopRequestLogStore (ctrl ), registry )
221242 ctx := context .Background ()
222243
223244 req := & pb.LandRequest {
0 commit comments