@@ -20,6 +20,7 @@ import (
2020 "go.mongodb.org/mongo-driver/v2/internal/assert"
2121 "go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
2222 "go.mongodb.org/mongo-driver/v2/internal/israce"
23+ "go.mongodb.org/mongo-driver/v2/internal/require"
2324 "go.mongodb.org/mongo-driver/v2/mongo"
2425 "go.mongodb.org/mongo-driver/v2/mongo/options"
2526)
@@ -74,19 +75,19 @@ func TestGridFS(x *testing.T) {
7475 bucket := mt .DB .GridFSBucket (options .GridFSBucket ().SetChunkSizeBytes (chunkSize ))
7576
7677 ustream , err := bucket .OpenUploadStream (context .Background (), "foo" )
77- assert . Nil (mt , err , "OpenUploadStream error: %v" , err )
78+ require . NoError (mt , err , "OpenUploadStream error: %v" , err )
7879
7980 id := ustream .FileID
8081 _ , err = ustream .Write (data )
81- assert . Nil (mt , err , "Write error: %v" , err )
82+ require . NoError (mt , err , "Write error: %v" , err )
8283 err = ustream .Close ()
83- assert . Nil (mt , err , "Close error: %v" , err )
84+ require . NoError (mt , err , "Close error: %v" , err )
8485
8586 dstream , err := bucket .OpenDownloadStream (context .Background (), id )
86- assert . Nil (mt , err , "OpenDownloadStream error" )
87+ require . NoError (mt , err , "OpenDownloadStream error" )
8788 dst := make ([]byte , tc .read )
8889 _ , err = dstream .Read (dst )
89- assert . Nil (mt , err , "Read error: %v" , err )
90+ require . NoError (mt , err , "Read error: %v" , err )
9091
9192 n , err := dstream .Skip (tc .skip )
9293 assert .Equal (mt , tc .expectedSkipErr , err , "expected error on Skip: %v, got %v" , tc .expectedSkipErr , err )
@@ -114,7 +115,7 @@ func TestGridFS(x *testing.T) {
114115 mt .Cleanup (cancel )
115116
116117 _ , err := bucket .UploadFromStream (uploadCtx , "filename" , r )
117- assert . Nil (mt , err , "UploadFromStream error: %v" , err )
118+ require . NoError (mt , err , "UploadFromStream error: %v" , err )
118119
119120 findCtx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
120121 mt .Cleanup (cancel )
@@ -169,7 +170,7 @@ func TestGridFS(x *testing.T) {
169170 }},
170171 },
171172 )
172- assert . Nil (mt , res .Err (), "createIndexes error: %v" , res .Err ())
173+ require . NoError (mt , res .Err (), "createIndexes error: %v" , res .Err ())
173174
174175 res = mt .DB .RunCommand (context .Background (),
175176 bson.D {
@@ -179,7 +180,7 @@ func TestGridFS(x *testing.T) {
179180 }},
180181 },
181182 )
182- assert . Nil (mt , res .Err (), "createIndexes error: %v" , res .Err ())
183+ require . NoError (mt , res .Err (), "createIndexes error: %v" , res .Err ())
183184
184185 mt .ClearEvents ()
185186
@@ -189,7 +190,7 @@ func TestGridFS(x *testing.T) {
189190 }()
190191
191192 _ , err := bucket .OpenUploadStream (context .Background (), "filename" )
192- assert . Nil (mt , err , "OpenUploadStream error: %v" , err )
193+ require . NoError (mt , err , "OpenUploadStream error: %v" , err )
193194
194195 mt .FilterStartedEvents (func (evt * event.CommandStartedEvent ) bool {
195196 return evt .CommandName == "createIndexes"
@@ -215,7 +216,7 @@ func TestGridFS(x *testing.T) {
215216 }},
216217 },
217218 )
218- assert . Nil (mt , res .Err (), "createIndexes error: %v" , res .Err ())
219+ require . NoError (mt , res .Err (), "createIndexes error: %v" , res .Err ())
219220
220221 res = mt .DB .RunCommand (context .Background (),
221222 bson.D {
@@ -225,7 +226,7 @@ func TestGridFS(x *testing.T) {
225226 }},
226227 },
227228 )
228- assert . Nil (mt , res .Err (), "createIndexes error: %v" , res .Err ())
229+ require . NoError (mt , res .Err (), "createIndexes error: %v" , res .Err ())
229230
230231 mt .ClearEvents ()
231232 var fileContent []byte
@@ -236,7 +237,7 @@ func TestGridFS(x *testing.T) {
236237 }()
237238
238239 _ , err := bucket .UploadFromStream (context .Background (), "filename" , bytes .NewBuffer (fileContent ))
239- assert . Nil (mt , err , "UploadFromStream error: %v" , err )
240+ require . NoError (mt , err , "UploadFromStream error: %v" , err )
240241
241242 mt .FilterStartedEvents (func (evt * event.CommandStartedEvent ) bool {
242243 return evt .CommandName == "createIndexes"
@@ -264,7 +265,7 @@ func TestGridFS(x *testing.T) {
264265 fileData := []byte {1 , 2 , 3 , 4 }
265266 fileMetadata := bson.D {{"k1" , "v1" }, {"k2" , "v2" }}
266267 rawMetadata , err := bson .Marshal (fileMetadata )
267- assert . Nil (mt , err , "Marshal error: %v" , err )
268+ require . NoError (mt , err , "Marshal error: %v" , err )
268269 uploadOpts := options .GridFSUpload ().SetMetadata (fileMetadata )
269270
270271 testCases := []struct {
@@ -288,13 +289,13 @@ func TestGridFS(x *testing.T) {
288289 } else {
289290 err = bucket .UploadFromStreamWithID (context .Background (), tc .fileID , fileName , dataReader , uploadOpts )
290291 }
291- assert . Nil (mt , err , "error uploading file: %v" , err )
292+ require . NoError (mt , err , "error uploading file: %v" , err )
292293
293294 // The uploadDate field is calculated when the upload is complete. Manually fetch it from the
294295 // fs.files collection to use in assertions.
295296 filesColl := mt .DB .Collection ("fs.files" )
296297 uploadedFileDoc , err := filesColl .FindOne (context .Background (), bson.D {}).Raw ()
297- assert . Nil (mt , err , "FindOne error: %v" , err )
298+ require . NoError (mt , err , "FindOne error: %v" , err )
298299 uploadTime := uploadedFileDoc .Lookup ("uploadDate" ).Time ().UTC ()
299300
300301 expectedFile := & mongo.GridFSFile {
@@ -309,13 +310,13 @@ func TestGridFS(x *testing.T) {
309310 // stream to the expected File object.
310311 mt .RunOpts ("OpenDownloadStream" , noClientOpts , func (mt * mtest.T ) {
311312 downloadStream , err := bucket .OpenDownloadStream (context .Background (), uploadedFileID )
312- assert . Nil (mt , err , "OpenDownloadStream error: %v" , err )
313+ require . NoError (mt , err , "OpenDownloadStream error: %v" , err )
313314 actualFile := downloadStream .GetFile ()
314315 assert .Equal (mt , expectedFile , actualFile , "expected file %v, got %v" , expectedFile , actualFile )
315316 })
316317 mt .RunOpts ("OpenDownloadStreamByName" , noClientOpts , func (mt * mtest.T ) {
317318 downloadStream , err := bucket .OpenDownloadStreamByName (context .Background (), fileName )
318- assert . Nil (mt , err , "OpenDownloadStream error: %v" , err )
319+ require . NoError (mt , err , "OpenDownloadStream error: %v" , err )
319320 actualFile := downloadStream .GetFile ()
320321 assert .Equal (mt , expectedFile , actualFile , "expected file %v, got %v" , expectedFile , actualFile )
321322 })
@@ -332,13 +333,13 @@ func TestGridFS(x *testing.T) {
332333 fileData := []byte ("hello world" )
333334 uploadOpts := options .GridFSUpload ().SetChunkSizeBytes (4 )
334335 fileID , err := bucket .UploadFromStream (context .Background (), "file" , bytes .NewReader (fileData ), uploadOpts )
335- assert . Nil (mt , err , "UploadFromStream error: %v" , err )
336+ require . NoError (mt , err , "UploadFromStream error: %v" , err )
336337
337338 // If the bucket's chunk size was used, this would error because the actual chunk size is 4 and the bucket
338339 // chunk size is 255 KB.
339340 var downloadBuffer bytes.Buffer
340341 _ , err = bucket .DownloadToStream (context .Background (), fileID , & downloadBuffer )
341- assert . Nil (mt , err , "DownloadToStream error: %v" , err )
342+ require . NoError (mt , err , "DownloadToStream error: %v" , err )
342343
343344 downloadedBytes := downloadBuffer .Bytes ()
344345 assert .Equal (mt , fileData , downloadedBytes , "expected bytes %s, got %s" , fileData , downloadedBytes )
@@ -354,7 +355,7 @@ func TestGridFS(x *testing.T) {
354355 {"filename" , "filename" },
355356 }
356357 _ , err := mt .DB .Collection ("fs.files" ).InsertOne (context .Background (), filesDoc )
357- assert . Nil (mt , err , "InsertOne error for files collection: %v" , err )
358+ require . NoError (mt , err , "InsertOne error for files collection: %v" , err )
358359
359360 bucket := mt .DB .GridFSBucket ()
360361 defer func () { _ = bucket .Drop (context .Background ()) }()
@@ -376,7 +377,7 @@ func TestGridFS(x *testing.T) {
376377
377378 dataReader := bytes .NewReader (fileData )
378379 _ , err := bucket .UploadFromStream (context .Background (), fileName , dataReader )
379- assert . Nil (mt , err , "UploadFromStream error: %v" , err )
380+ require . NoError (mt , err , "UploadFromStream error: %v" , err )
380381
381382 ctx , cancel := context .WithCancel (context .Background ())
382383
@@ -403,17 +404,17 @@ func TestGridFS(x *testing.T) {
403404
404405 dataReader := bytes .NewReader (fileData )
405406 _ , err := bucket .UploadFromStream (context .Background (), fileName , dataReader )
406- assert . Nil (mt , err , "UploadFromStream error: %v" , err )
407+ require . NoError (mt , err , "UploadFromStream error: %v" , err )
407408
408409 ctx , cancel := context .WithCancel (context .Background ())
409410
410411 ds , err := bucket .OpenDownloadStreamByName (ctx , fileName )
411- assert . Nil (mt , err , "OpenDownloadStreamByName error: %v" , err )
412+ require . NoError (mt , err , "OpenDownloadStreamByName error: %v" , err )
412413
413414 cancel ()
414415
415416 _ , err = ds .Skip (int64 (len (fileData )))
416- assert .NotNil (mt , err , "expected error from Skip, got nil " )
417+ assert .Error (mt , err , "expected error from Skip" )
417418 assert .ErrorIs (mt , context .Canceled , err )
418419 })
419420 })
@@ -441,7 +442,7 @@ func TestGridFS(x *testing.T) {
441442 defer func () { _ = bucket .Drop (context .Background ()) }()
442443
443444 _ , err := bucket .UploadFromStream (context .Background (), "accessors-test-file" , bytes .NewReader (fileData ))
444- assert . Nil (mt , err , "UploadFromStream error: %v" , err )
445+ require . NoError (mt , err , "UploadFromStream error: %v" , err )
445446
446447 bucketName := tc .bucketName
447448 if bucketName == "" {
@@ -499,7 +500,7 @@ func TestGridFS(x *testing.T) {
499500 mt .Cleanup (cancel )
500501
501502 _ , err := bucket .UploadFromStream (ctx , "filename" , bytes .NewReader (p ))
502- assert . Nil (mt , err , "UploadFromStream error: %v" , err )
503+ require . NoError (mt , err , "UploadFromStream error: %v" , err )
503504
504505 var w * bytes.Buffer
505506 if test .bufSize == - 1 {
@@ -509,7 +510,7 @@ func TestGridFS(x *testing.T) {
509510 }
510511
511512 _ , err = bucket .DownloadToStreamByName (ctx , "filename" , w )
512- assert . Nil (mt , err , "DownloadToStreamByName error: %v" , err )
513+ require . NoError (mt , err , "DownloadToStreamByName error: %v" , err )
513514 assert .Equal (mt , p , w .Bytes (), "downloaded file did not match p" )
514515 })
515516 }
@@ -524,7 +525,7 @@ func TestGridFS(x *testing.T) {
524525 _ = cursor .Close (context .Background ())
525526 }()
526527
527- assert .Nil (mt , err , "Find error: %v" , err )
528+ assert .NoError (mt , err , "Find error: %v" , err )
528529 })
529530}
530531
@@ -533,15 +534,15 @@ func assertGridFSCollectionState(mt *mtest.T, coll *mongo.Collection, expectedNa
533534
534535 assert .Equal (mt , expectedName , coll .Name (), "expected collection name %v, got %v" , expectedName , coll .Name ())
535536 count , err := coll .CountDocuments (context .Background (), bson.D {})
536- assert . Nil (mt , err , "CountDocuments error: %v" , err )
537+ require . NoError (mt , err , "CountDocuments error: %v" , err )
537538 assert .Equal (mt , expectedNumDocuments , count , "expected %d documents in collection, got %d" , expectedNumDocuments ,
538539 count )
539540}
540541
541542func findIndex (ctx context.Context , mt * mtest.T , coll * mongo.Collection , unique bool , keys ... string ) {
542543 mt .Helper ()
543544 cur , err := coll .Indexes ().List (ctx )
544- assert . Nil (mt , err , "Indexes List error: %v" , err )
545+ require . NoError (mt , err , "Indexes List error: %v" , err )
545546
546547 foundIndex := false
547548 for cur .Next (ctx ) {
@@ -566,7 +567,7 @@ func skipRoundTripTest(mt *mtest.T) {
566567 context .Background (),
567568 bson.D {{"serverStatus" , 1 }},
568569 ).Decode (& serverStatus )
569- assert . Nil (mt , err , "serverStatus error %v" , err )
570+ require . NoError (mt , err , "serverStatus error %v" , err )
570571
571572 // can run on non-sharded clusters or on sharded cluster with auth/ssl disabled
572573 _ , err = serverStatus .LookupErr ("sharding" )
0 commit comments