@@ -10,9 +10,8 @@ const core = require('mongodb-core');
10
10
const sessions = core . Sessions ;
11
11
const environments = require ( '../environments' ) ;
12
12
13
- // mlaunch init --replicaset --arbiter --name rs --hostname localhost --port 31000 --setParameter enableTestCommands=1 --binarypath /Users/mbroadst/Downloads/mongodb-osx-x86_64-enterprise-4.1.0-158-g3d62f3c/bin
14
-
15
13
chai . use ( require ( 'chai-subset' ) ) ;
14
+ chai . use ( require ( '../match_transaction_spec' ) . default ) ;
16
15
chai . config . includeStack = true ;
17
16
chai . config . showDiff = true ;
18
17
chai . config . truncateThreshold = 0 ;
@@ -23,55 +22,6 @@ function isPlainObject(value) {
23
22
24
23
process . on ( 'unhandledRejection' , err => console . dir ( err ) ) ;
25
24
26
- /**
27
- * Finds placeholder values in a deeply nested object.
28
- *
29
- * NOTE: This also mutates the object, by removing the values for comparison
30
- *
31
- * @param {Object } input the object to find placeholder values in
32
- */
33
- function findPlaceholders ( value , parent ) {
34
- return Object . keys ( value ) . reduce ( ( result , key ) => {
35
- if ( isPlainObject ( value [ key ] ) ) {
36
- return result . concat (
37
- findPlaceholders ( value [ key ] , [ value , key ] ) . map ( x => {
38
- if ( x . path . startsWith ( '$' ) ) {
39
- x . path = key ;
40
- } else {
41
- x . path = `${ key } .${ x . path } ` ;
42
- }
43
-
44
- return x ;
45
- } )
46
- ) ;
47
- }
48
-
49
- if ( value [ key ] === null ) {
50
- delete value [ key ] ;
51
- result . push ( { path : key , type : null } ) ;
52
- } else if ( value [ key ] === 42 || value [ key ] === '42' ) {
53
- if ( key . startsWith ( '$number' ) ) {
54
- result . push ( { path : key , type : 'number' } ) ;
55
- } else if ( value [ key ] === 42 ) {
56
- result . push ( { path : key , type : 'exists' } ) ;
57
- } else {
58
- result . push ( { path : key , type : 'string' } ) ;
59
- }
60
-
61
- // NOTE: fix this, it just passes the current examples
62
- if ( parent == null ) {
63
- delete value [ key ] ;
64
- } else {
65
- delete parent [ 0 ] [ parent [ 1 ] ] ;
66
- }
67
- } else if ( value [ key ] === '' ) {
68
- result . push ( { path : key , type : 'string' } ) ;
69
- }
70
-
71
- return result ;
72
- } , [ ] ) ;
73
- }
74
-
75
25
function translateClientOptions ( options ) {
76
26
Object . keys ( options ) . forEach ( key => {
77
27
if ( key === 'readConcernLevel' ) {
@@ -400,18 +350,19 @@ function runTestSuiteTest(configuration, spec, context) {
400
350
Object . assign ( { } , sessionOptions , parseSessionOptions ( spec . sessionOptions . session1 ) )
401
351
) ;
402
352
353
+ const savedSessionData = {
354
+ session0 : JSON . parse ( EJSON . stringify ( session0 . id ) ) ,
355
+ session1 : JSON . parse ( EJSON . stringify ( session1 . id ) )
356
+ } ;
357
+
403
358
// enable to see useful APM debug information at the time of actual test run
404
359
// displayCommands = true;
405
360
406
361
const operationContext = {
407
362
database,
408
363
session0,
409
364
session1,
410
- testRunner : context ,
411
- savedSessionData : {
412
- session0 : JSON . parse ( EJSON . stringify ( session0 . id ) ) ,
413
- session1 : JSON . parse ( EJSON . stringify ( session1 . id ) )
414
- }
365
+ testRunner : context
415
366
} ;
416
367
417
368
let testPromise = Promise . resolve ( ) ;
@@ -426,7 +377,7 @@ function runTestSuiteTest(configuration, spec, context) {
426
377
session0 . endSession ( ) ;
427
378
session1 . endSession ( ) ;
428
379
429
- return validateExpectations ( commandEvents , spec , context , operationContext ) ;
380
+ return validateExpectations ( commandEvents , spec , savedSessionData ) ;
430
381
} ) ;
431
382
} ) ;
432
383
}
@@ -448,65 +399,28 @@ function validateOutcome(testData, testContext) {
448
399
return Promise . resolve ( ) ;
449
400
}
450
401
451
- function validateExpectations ( commandEvents , spec , testContext , operationContext ) {
402
+ function validateExpectations ( commandEvents , spec , savedSessionData ) {
452
403
if ( spec . expectations && Array . isArray ( spec . expectations ) && spec . expectations . length > 0 ) {
453
404
const actualEvents = normalizeCommandShapes ( commandEvents ) ;
454
- const rawExpectedEvents = spec . expectations . map ( x =>
455
- linkSessionData ( x . command_started_event , operationContext . savedSessionData )
456
- ) ;
457
-
458
- const expectedEventPlaceholders = rawExpectedEvents . map ( event =>
459
- findPlaceholders ( event . command )
460
- ) ;
461
-
405
+ const rawExpectedEvents = spec . expectations . map ( x => x . command_started_event ) ;
462
406
const expectedEvents = normalizeCommandShapes ( rawExpectedEvents ) ;
463
407
expect ( actualEvents ) . to . have . length ( expectedEvents . length ) ;
464
408
465
409
expectedEvents . forEach ( ( expected , idx ) => {
466
410
const actual = actualEvents [ idx ] ;
467
- const placeHolders = expectedEventPlaceholders [ idx ] ; // eslint-disable-line
468
411
469
412
expect ( actual . commandName ) . to . equal ( expected . commandName ) ;
470
413
expect ( actual . databaseName ) . to . equal ( expected . databaseName ) ;
471
414
472
415
const actualCommand = actual . command ;
473
416
const expectedCommand = expected . command ;
474
417
475
- // handle validation of placeholder values
476
- // placeHolders.forEach(placeholder => {
477
- // const parsedActual = EJSON.parse(JSON.stringify(actualCommand), {
478
- // relaxed: true
479
- // });
480
-
481
- // if (placeholder.type === null) {
482
- // expect(parsedActual).to.not.have.all.nested.property(placeholder.path);
483
- // } else if (placeholder.type === 'string') {
484
- // expect(parsedActual).nested.property(placeholder.path).to.exist;
485
- // expect(parsedActual)
486
- // .nested.property(placeholder.path)
487
- // .to.have.length.greaterThan(0);
488
- // } else if (placeholder.type === 'number') {
489
- // expect(parsedActual).nested.property(placeholder.path).to.exist;
490
- // expect(parsedActual)
491
- // .nested.property(placeholder.path)
492
- // .to.be.greaterThan(0);
493
- // } else if (placeholder.type === 'exists') {
494
- // expect(parsedActual).nested.property(placeholder.path).to.exist;
495
- // }
496
- // });
497
-
498
- // compare the command
499
- expect ( actualCommand ) . to . containSubset ( expectedCommand ) ;
418
+ expect ( actualCommand )
419
+ . withSessionData ( savedSessionData )
420
+ . to . matchTransactionSpec ( expectedCommand ) ;
500
421
} ) ;
501
422
}
502
423
}
503
-
504
- function linkSessionData ( command , context ) {
505
- const result = Object . assign ( { } , command ) ;
506
- result . command . lsid = context [ command . command . lsid ] ;
507
- return result ;
508
- }
509
-
510
424
function normalizeCommandShapes ( commands ) {
511
425
return commands . map ( command =>
512
426
JSON . parse (
0 commit comments