@@ -22,7 +22,6 @@ import (
2222 "github.com/stretchr/testify/assert"
2323 "github.com/stretchr/testify/require"
2424 "github.com/uber-go/tally"
25- pb "github.com/uber/submitqueue/api/submitqueue/gateway/protopb"
2625 entityqueue "github.com/uber/submitqueue/platform/base/messagequeue"
2726 "github.com/uber/submitqueue/platform/consumer"
2827 "github.com/uber/submitqueue/platform/errs"
@@ -68,6 +67,11 @@ func newRequestLogStoreNoop(t *testing.T, ctrl *gomock.Controller) *storagemock.
6867 return store
6968}
7069
70+ // testCancelRequest returns a valid entity.CancelRequest for testing.
71+ func testCancelRequest (sqid string , reason string ) entity.CancelRequest {
72+ return entity.CancelRequest {ID : sqid , Reason : reason }
73+ }
74+
7175func TestNewCancelController (t * testing.T ) {
7276 ctrl := gomock .NewController (t )
7377
@@ -81,11 +85,9 @@ func TestCancel_HappyPath(t *testing.T) {
8185 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , newRequestLogStoreNoop (t , ctrl ), newCancelTestRegistryWithNoopPublisher (t , ctrl ))
8286 ctx := context .Background ()
8387
84- req := & pb.CancelRequest {Sqid : "test-queue/42" , Reason : "user changed their mind" }
85- resp , err := controller .Cancel (ctx , req )
88+ err := controller .Cancel (ctx , testCancelRequest ("test-queue/42" , "user changed their mind" ))
8689
8790 require .NoError (t , err )
88- require .NotNil (t , resp )
8991}
9092
9193func TestCancel_ReturnsErrorOnEmptySqid (t * testing.T ) {
@@ -94,8 +96,7 @@ func TestCancel_ReturnsErrorOnEmptySqid(t *testing.T) {
9496 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , newRequestLogStoreNoop (t , ctrl ), newCancelTestRegistryWithNoopPublisher (t , ctrl ))
9597 ctx := context .Background ()
9698
97- req := & pb.CancelRequest {Sqid : "" , Reason : "anything" }
98- _ , err := controller .Cancel (ctx , req )
99+ err := controller .Cancel (ctx , testCancelRequest ("" , "anything" ))
99100
100101 require .Error (t , err )
101102 assert .True (t , IsInvalidRequest (err ))
@@ -119,8 +120,7 @@ func TestCancel_PublishesToQueue(t *testing.T) {
119120 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , newRequestLogStoreNoop (t , ctrl ), registry )
120121 ctx := context .Background ()
121122
122- req := & pb.CancelRequest {Sqid : "my-queue/7" , Reason : "obsolete change" }
123- _ , err := controller .Cancel (ctx , req )
123+ err := controller .Cancel (ctx , testCancelRequest ("my-queue/7" , "obsolete change" ))
124124 require .NoError (t , err )
125125
126126 assert .Equal (t , "cancel" , publishedTopic )
@@ -160,8 +160,7 @@ func TestCancel_InsertsCancellingLog(t *testing.T) {
160160
161161 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , logStore , registry )
162162
163- req := & pb.CancelRequest {Sqid : "my-queue/42" , Reason : "obsolete change" }
164- _ , err := controller .Cancel (context .Background (), req )
163+ err := controller .Cancel (context .Background (), testCancelRequest ("my-queue/42" , "obsolete change" ))
165164 require .NoError (t , err )
166165
167166 assert .Equal (t , "my-queue/42" , insertedLog .RequestID )
@@ -180,11 +179,10 @@ func TestCancel_LogInsertFailure(t *testing.T) {
180179 logStore .EXPECT ().Insert (gomock .Any (), gomock .Any ()).Return (fmt .Errorf ("db unavailable" ))
181180
182181 registry , publisher := newCancelTestRegistry (t , ctrl )
183- // No Publish expectation: log insert must fail before publish runs.
184182 _ = publisher
185183
186184 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , logStore , registry )
187- _ , err := controller .Cancel (context .Background (), & pb. CancelRequest { Sqid : "q/1" } )
185+ err := controller .Cancel (context .Background (), testCancelRequest ( "q/1" , "" ) )
188186 require .Error (t , err )
189187}
190188
@@ -197,8 +195,7 @@ func TestCancel_ReturnsErrorOnPublishFailure(t *testing.T) {
197195 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , newRequestLogStoreNoop (t , ctrl ), registry )
198196 ctx := context .Background ()
199197
200- req := & pb.CancelRequest {Sqid : "test-queue/1" }
201- _ , err := controller .Cancel (ctx , req )
198+ err := controller .Cancel (ctx , testCancelRequest ("test-queue/1" , "" ))
202199
203200 require .Error (t , err )
204201}
@@ -211,14 +208,12 @@ func TestCancel_UnknownSqidIsUserError(t *testing.T) {
211208
212209 logStore := storagemock .NewMockRequestLogStore (ctrl )
213210 logStore .EXPECT ().List (gomock .Any (), "ghost/1" ).Return (nil , storage .ErrNotFound )
214- // No Insert expectation: existence check must short-circuit before Insert.
215211
216212 registry , publisher := newCancelTestRegistry (t , ctrl )
217- // No Publish expectation: existence check must short-circuit before Publish.
218213 _ = publisher
219214
220215 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , logStore , registry )
221- _ , err := controller .Cancel (context .Background (), & pb. CancelRequest { Sqid : "ghost/1" } )
216+ err := controller .Cancel (context .Background (), testCancelRequest ( "ghost/1" , "" ) )
222217 require .Error (t , err )
223218 assert .True (t , IsRequestNotFound (err ))
224219 assert .True (t , errs .IsUserError (err ))
@@ -242,7 +237,7 @@ func TestCancel_RequestLogLookupFailure(t *testing.T) {
242237 _ = publisher
243238
244239 controller := NewCancelController (zap .NewNop ().Sugar (), tally .NoopScope , logStore , registry )
245- _ , err := controller .Cancel (context .Background (), & pb. CancelRequest { Sqid : "q/1" } )
240+ err := controller .Cancel (context .Background (), testCancelRequest ( "q/1" , "" ) )
246241 require .Error (t , err )
247242 assert .False (t , errs .IsUserError (err ))
248243 assert .False (t , IsRequestNotFound (err ))
0 commit comments