@@ -3,7 +3,7 @@ import { expect } from 'chai';
3
3
import { MongoClient } from 'mongodb' ;
4
4
import { eventually } from './helpers' ;
5
5
import { TestShell } from './test-shell' ;
6
- import { startTestServer } from '../../../testing/integration-testing-hooks' ;
6
+ import { startTestServer , skipIfServerVersion } from '../../../testing/integration-testing-hooks' ;
7
7
import { promises as fs , createReadStream } from 'fs' ;
8
8
import { promisify } from 'util' ;
9
9
import rimraf from 'rimraf' ;
@@ -839,5 +839,63 @@ describe('e2e', function() {
839
839
} ) ;
840
840
} ) ;
841
841
} ) ;
842
+
843
+ describe ( 'versioned API' , ( ) => {
844
+ let db ;
845
+ let dbName ;
846
+ let client ;
847
+
848
+ beforeEach ( async ( ) => {
849
+ dbName = `test-${ Date . now ( ) } ` ;
850
+
851
+ client = await MongoClient . connect ( await testServer . connectionString ( ) , { } ) ;
852
+ db = client . db ( dbName ) ;
853
+ } ) ;
854
+
855
+ afterEach ( async ( ) => {
856
+ await db . dropDatabase ( ) ;
857
+ client . close ( ) ;
858
+ } ) ;
859
+
860
+
861
+ context ( 'pre-4.4' , ( ) => {
862
+ skipIfServerVersion ( testServer , '> 4.4' ) ;
863
+
864
+ it ( 'errors if an API version is specified' , async ( ) => {
865
+ const shell = TestShell . start ( { args : [
866
+ `${ await testServer . connectionString ( ) } /${ dbName } ` , '--apiVersion' , '1'
867
+ ] } ) ;
868
+ await shell . waitForPrompt ( ) ;
869
+ expect ( await shell . executeLine ( 'db.coll.find().toArray()' ) )
870
+ . to . include ( "Unrecognized field 'apiVersion'" ) ;
871
+ } ) ;
872
+ } ) ;
873
+
874
+ context ( 'post-4.4' , ( ) => {
875
+ skipIfServerVersion ( testServer , '<= 4.4' ) ;
876
+
877
+ it ( 'can specify an API version' , async ( ) => {
878
+ const shell = TestShell . start ( { args : [
879
+ `${ await testServer . connectionString ( ) } /${ dbName } ` , '--apiVersion' , '1'
880
+ ] } ) ;
881
+ await shell . waitForPrompt ( ) ;
882
+ expect ( await shell . executeLine ( 'db.coll.find().toArray()' ) )
883
+ . to . include ( '[]' ) ;
884
+ shell . assertNoErrors ( ) ;
885
+ } ) ;
886
+
887
+ it ( 'can iterate cursors' , async ( ) => {
888
+ // Make sure SERVER-55593 doesn't happen to us.
889
+ const shell = TestShell . start ( { args : [
890
+ `${ await testServer . connectionString ( ) } /${ dbName } ` , '--apiVersion' , '1'
891
+ ] } ) ;
892
+ await shell . waitForPrompt ( ) ;
893
+ await shell . executeLine ( 'for (let i = 0; i < 200; i++) db.coll.insert({i})' ) ;
894
+ await shell . executeLine ( 'const cursor = db.coll.find().limit(100).batchSize(10);' ) ;
895
+ expect ( await shell . executeLine ( 'cursor.toArray()' ) ) . to . include ( 'i: 5' ) ;
896
+ shell . assertNoErrors ( ) ;
897
+ } ) ;
898
+ } ) ;
899
+ } ) ;
842
900
} ) ;
843
901
0 commit comments