@@ -155,30 +155,42 @@ func TestCursor_RemainingBatchLength(t *testing.T) {
155155
156156 // The initial batch length should be equal to the batchSize. Do batchSize Next calls to exhaust the current
157157 // batch and assert that no getMore was done.
158- assertCursorBatchLength (mt , cursor , batchSize )
158+ assert .Equal (mt ,
159+ batchSize ,
160+ cursor .RemainingBatchLength (),
161+ "expected remaining batch length to match" )
159162 for i := 0 ; i < batchSize ; i ++ {
160163 prevLength := cursor .RemainingBatchLength ()
161164 if ! cursor .Next (context .Background ()) {
162165 mt .Fatalf ("expected Next to return true on index %d; cursor err: %v" , i , cursor .Err ())
163166 }
164167
165168 // Each successful Next call should decrement batch length by 1.
166- assertCursorBatchLength (mt , cursor , prevLength - 1 )
169+ assert .Equal (mt ,
170+ prevLength - 1 ,
171+ cursor .RemainingBatchLength (),
172+ "expected remaining batch length to match" )
167173 }
168174 evt := mt .GetStartedEvent ()
169175 assert .Nil (mt , evt , "expected no events, got %v" , evt )
170176
171177 // The batch is exhausted, so the batch length should be 0. Do one Next call, which should do a getMore and
172178 // fetch batchSize more documents. The batch length after the call should be (batchSize-1) because Next consumes
173179 // one document.
174- assertCursorBatchLength (mt , cursor , 0 )
180+ assert .Equal (mt ,
181+ 0 ,
182+ cursor .RemainingBatchLength (),
183+ "expected remaining batch length to match" )
175184
176185 assert .True (mt , cursor .Next (context .Background ()), "expected Next to return true; cursor err: %v" , cursor .Err ())
177186 evt = mt .GetStartedEvent ()
178187 assert .NotNil (mt , evt , "expected CommandStartedEvent, got nil" )
179188 assert .Equal (mt , "getMore" , evt .CommandName , "expected command %q, got %q" , "getMore" , evt .CommandName )
180189
181- assertCursorBatchLength (mt , cursor , batchSize - 1 )
190+ assert .Equal (mt ,
191+ batchSize - 1 ,
192+ cursor .RemainingBatchLength (),
193+ "expected remaining batch length to match" )
182194 })
183195 mt .RunOpts ("first batch is empty" , mtest .NewOptions ().ClientType (mtest .Mock ), func (mt * mtest.T ) {
184196 // Test that the cursor reports the correct value for RemainingBatchLength if the first batch is empty.
@@ -209,10 +221,16 @@ func TestCursor_RemainingBatchLength(t *testing.T) {
209221 }
210222
211223 assert .Nil (mt , cursor .Err (), "cursor error: %v" , err )
212- assertCursorBatchLength (mt , cursor , 0 )
224+ assert .Equal (mt ,
225+ 0 ,
226+ cursor .RemainingBatchLength (),
227+ "expected remaining batch length to match" )
213228 }
214229 // TryNext consumes one document so the remaining batch size should be len(getMoreBatch)-1.
215- assertCursorBatchLength (mt , cursor , len (getMoreBatch )- 1 )
230+ assert .Equal (mt ,
231+ len (getMoreBatch )- 1 ,
232+ cursor .RemainingBatchLength (),
233+ "expected remaining batch length to match" )
216234 })
217235}
218236
@@ -617,8 +635,3 @@ func tryNextGetmoreError(mt *mtest.T, cursor tryNextCursor) {
617635 assert .Equal (mt , testErr .Name , mongoErr .Name , "expected name %v, got: %v" , testErr .Name , mongoErr .Name )
618636 assert .Equal (mt , testErr .Labels , mongoErr .Labels , "expected labels %v, got: %v" , testErr .Labels , mongoErr .Labels )
619637}
620-
621- func assertCursorBatchLength (mt * mtest.T , cursor * mongo.Cursor , expected int ) {
622- batchLen := cursor .RemainingBatchLength ()
623- assert .Equal (mt , expected , batchLen , "expected remaining batch length %d, got %d" , expected , batchLen )
624- }
0 commit comments