File tree Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -1593,7 +1593,7 @@ describe('Collection', () => {
1593
1593
}
1594
1594
) ;
1595
1595
} ) ;
1596
- it ( 'calls serviceProvider.runCommand on the collection with options ' , async ( ) => {
1596
+ it ( 'calls serviceProvider.runCommand on the collection with boolean argument ' , async ( ) => {
1597
1597
await collection . validate ( true ) ;
1598
1598
expect ( serviceProvider . runCommandWithCheck ) . to . have . been . calledWith (
1599
1599
database . _name ,
@@ -1603,6 +1603,17 @@ describe('Collection', () => {
1603
1603
}
1604
1604
) ;
1605
1605
} ) ;
1606
+ it ( 'calls serviceProvider.runCommand on the collection with options' , async ( ) => {
1607
+ await collection . validate ( { full : true , repair : true } ) ;
1608
+ expect ( serviceProvider . runCommandWithCheck ) . to . have . been . calledWith (
1609
+ database . _name ,
1610
+ {
1611
+ validate : collection . _name ,
1612
+ full : true ,
1613
+ repair : true
1614
+ }
1615
+ ) ;
1616
+ } ) ;
1606
1617
1607
1618
it ( 'returns whatever serviceProvider.runCommand returns' , async ( ) => {
1608
1619
const expectedResult = { ok : 1 } ;
Original file line number Diff line number Diff line change @@ -1578,13 +1578,16 @@ export default class Collection extends ShellApiWithMongoClass {
1578
1578
1579
1579
@returnsPromise
1580
1580
@apiVersions ( [ ] )
1581
- async validate ( full = false ) : Promise < Document > {
1582
- this . _emitCollectionApiCall ( 'validate' , { full } ) ;
1581
+ async validate ( options : boolean | Document = false ) : Promise < Document > {
1582
+ this . _emitCollectionApiCall ( 'validate' , { options } ) ;
1583
+ if ( typeof options === 'boolean' ) {
1584
+ options = { full : options } ;
1585
+ }
1583
1586
return await this . _mongo . _serviceProvider . runCommandWithCheck (
1584
1587
this . _database . _name ,
1585
1588
{
1586
1589
validate : this . _name ,
1587
- full : full
1590
+ ... options
1588
1591
} ,
1589
1592
this . _database . _baseOptions
1590
1593
) ;
Original file line number Diff line number Diff line change @@ -1003,6 +1003,36 @@ describe('Shell API (integration)', function() {
1003
1003
expect ( await collection . findOne ( ) ) . to . deep . equal ( { '$x.y' : 2 , _id : '_id' } ) ;
1004
1004
} ) ;
1005
1005
} ) ;
1006
+
1007
+ describe ( 'validate' , ( ) => {
1008
+ skipIfApiStrict ( ) ;
1009
+ skipIfServerVersion ( testServer , '< 5.0' ) ;
1010
+
1011
+ beforeEach ( async ( ) => {
1012
+ await collection . insertOne ( { foo : 'bar' } ) ;
1013
+ } ) ;
1014
+
1015
+ it ( 'validate can be used to validate a collection' , async ( ) => {
1016
+ expect ( ( await collection . validate ( { full : true } ) ) . valid ) . to . equal ( true ) ;
1017
+ } ) ;
1018
+
1019
+ it ( 'validate accepts a repair option' , async ( ) => {
1020
+ expect ( ( await collection . validate ( { full : true , repair : true } ) ) . valid ) . to . equal ( true ) ;
1021
+ } ) ;
1022
+
1023
+ it ( 'validate accepts a background option' , async ( ) => {
1024
+ expect ( ( await collection . validate ( { full : false , background : true } ) ) . valid ) . to . equal ( true ) ;
1025
+ } ) ;
1026
+
1027
+ it ( 'validate fails with background: true and full: true' , async ( ) => {
1028
+ try {
1029
+ await collection . validate ( { full : true , background : true } ) ;
1030
+ expect . fail ( 'missed exception' ) ;
1031
+ } catch ( err ) {
1032
+ expect ( err . name ) . to . equal ( 'MongoServerError' ) ;
1033
+ }
1034
+ } ) ;
1035
+ } ) ;
1006
1036
} ) ;
1007
1037
1008
1038
describe ( 'db' , ( ) => {
You can’t perform that action at this time.
0 commit comments