Skip to content

Commit

Permalink
test(NODE-3412): sync spec tests for serverless testing (#2911)
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum committed Jul 19, 2021
1 parent 51ea86d commit d270610
Show file tree
Hide file tree
Showing 331 changed files with 16,364 additions and 11,231 deletions.
2 changes: 1 addition & 1 deletion src/collection.ts
Expand Up @@ -1237,11 +1237,11 @@ export class Collection<TSchema extends Document = Document> {
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
findOneAndDelete(filter: Filter<TSchema>): Promise<ModifyResult<TSchema>>;
findOneAndDelete(filter: Filter<TSchema>, callback: Callback<ModifyResult<TSchema>>): void;
findOneAndDelete(
filter: Filter<TSchema>,
options: FindOneAndDeleteOptions
): Promise<ModifyResult<TSchema>>;
findOneAndDelete(filter: Filter<TSchema>, callback: Callback<ModifyResult<TSchema>>): void;
findOneAndDelete(
filter: Filter<TSchema>,
options: FindOneAndDeleteOptions,
Expand Down
15 changes: 0 additions & 15 deletions test/functional/crud_spec.test.js
Expand Up @@ -6,10 +6,6 @@ const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-subset'));

const TestRunnerContext = require('./spec-runner').TestRunnerContext;
const gatherTestSuites = require('./spec-runner').gatherTestSuites;
const generateTopologyTests = require('./spec-runner').generateTopologyTests;

const { loadSpecTests } = require('../spec/index');
const { runUnifiedTest } = require('./unified-spec-runner/runner');

Expand Down Expand Up @@ -425,17 +421,6 @@ describe('CRUD spec', function () {
}
});

describe('CRUD v2', function () {
const testContext = new TestRunnerContext();
const testSuites = gatherTestSuites(path.resolve(__dirname, '../spec/crud/v2'));
after(() => testContext.teardown());
before(function () {
return testContext.setup(this.configuration);
});

generateTopologyTests(testSuites, testContext);
});

describe('CRUD unified', function () {
for (const crudSpecTest of loadSpecTests('crud/unified')) {
expect(crudSpecTest).to.exist;
Expand Down
12 changes: 6 additions & 6 deletions test/functional/unified-spec-runner/operations.ts
Expand Up @@ -270,6 +270,12 @@ operations.set('findOneAndUpdate', async ({ entities, operation }) => {
return (await collection.findOneAndUpdate(filter, update, translateOptions(opts))).value;
});

operations.set('findOneAndDelete', async ({ entities, operation }) => {
const collection = entities.getEntity('collection', operation.object);
const { filter, ...opts } = operation.arguments;
return (await collection.findOneAndDelete(filter, opts)).value;
});

operations.set('failPoint', async ({ entities, operation }) => {
const client = entities.getEntity('client', operation.arguments.client);
return entities.failPoints.enableFailPoint(client, operation.arguments.failPoint);
Expand Down Expand Up @@ -409,12 +415,6 @@ operations.set('estimatedDocumentCount', async ({ entities, operation }) => {
return collection.estimatedDocumentCount(operation.arguments);
});

operations.set('findOneAndDelete', async ({ entities, operation }) => {
const collection = entities.getEntity('collection', operation.object);
const { filter, ...opts } = operation.arguments;
return collection.findOneAndDelete(filter, opts);
});

operations.set('runCommand', async ({ entities, operation }: OperationFunctionParams) => {
const db = entities.getEntity('db', operation.object);
const { command, ...opts } = operation.arguments;
Expand Down
183 changes: 182 additions & 1 deletion test/spec/crud/unified/aggregate-let.json
@@ -1,6 +1,6 @@
{
"description": "aggregate-let",
"schemaVersion": "1.0",
"schemaVersion": "1.4",
"createEntities": [
{
"client": {
Expand All @@ -23,6 +23,13 @@
"database": "database0",
"collectionName": "coll0"
}
},
{
"collection": {
"id": "collection1",
"database": "database0",
"collectionName": "coll1"
}
}
],
"initialData": [
Expand All @@ -34,6 +41,11 @@
"_id": 1
}
]
},
{
"collectionName": "coll1",
"databaseName": "crud-tests",
"documents": []
}
],
"tests": [
Expand Down Expand Up @@ -293,6 +305,175 @@
]
}
]
},
{
"description": "Aggregate to collection with let option",
"runOnRequirements": [
{
"minServerVersion": "5.0",
"serverless": "forbid"
}
],
"operations": [
{
"name": "aggregate",
"object": "collection0",
"arguments": {
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
},
{
"$project": {
"_id": 1
}
},
{
"$out": "coll1"
}
],
"let": {
"id": 1
}
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"aggregate": "coll0",
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
},
{
"$project": {
"_id": 1
}
},
{
"$out": "coll1"
}
],
"let": {
"id": 1
}
}
}
}
]
}
],
"outcome": [
{
"collectionName": "coll1",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1
}
]
}
]
},
{
"description": "Aggregate to collection with let option unsupported (server-side error)",
"runOnRequirements": [
{
"minServerVersion": "2.6.0",
"maxServerVersion": "4.4.99"
}
],
"operations": [
{
"name": "aggregate",
"object": "collection0",
"arguments": {
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
},
{
"$project": {
"_id": 1
}
},
{
"$out": "coll1"
}
],
"let": {
"id": 1
}
},
"expectError": {
"errorContains": "unrecognized field 'let'",
"isClientError": false
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"aggregate": "coll0",
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
},
{
"$project": {
"_id": 1
}
},
{
"$out": "coll1"
}
],
"let": {
"id": 1
}
}
}
}
]
}
]
}
]
}
59 changes: 58 additions & 1 deletion test/spec/crud/unified/aggregate-let.yml
@@ -1,6 +1,6 @@
description: "aggregate-let"

schemaVersion: "1.0"
schemaVersion: "1.4"

createEntities:
- client:
Expand All @@ -14,12 +14,19 @@ createEntities:
id: &collection0 collection0
database: *database0
collectionName: &collection0Name coll0
- collection:
id: &collection1 collection1
database: *database0
collectionName: &collection1Name coll1

initialData: &initialData
- collectionName: *collection0Name
databaseName: *database0Name
documents:
- { _id: 1 }
- collectionName: *collection1Name
databaseName: *database0Name
documents: [ ]

tests:
# TODO: Once SERVER-57403 is resolved, this test can be removed in favor of
Expand Down Expand Up @@ -115,3 +122,53 @@ tests:
aggregate: *collection0Name
pipeline: *pipeline1
let: *let1

- description: "Aggregate to collection with let option"
runOnRequirements:
- minServerVersion: "5.0"
serverless: "forbid"
operations:
- name: aggregate
object: *collection0
arguments:
pipeline: &pipeline2
- $match: { $expr: { $eq: ["$_id", "$$id"] } }
- $project: { _id: 1 }
- $out: *collection1Name
let: &let2
id: 1
expectEvents:
- client: *client0
events:
- commandStartedEvent:
command:
aggregate: *collection0Name
pipeline: *pipeline2
let: *let2
outcome:
- collectionName: *collection1Name
databaseName: *database0Name
documents:
- { _id: 1 }

- description: "Aggregate to collection with let option unsupported (server-side error)"
runOnRequirements:
- minServerVersion: "2.6.0"
maxServerVersion: "4.4.99"
operations:
- name: aggregate
object: *collection0
arguments:
pipeline: *pipeline2
let: *let2
expectError:
errorContains: "unrecognized field 'let'"
isClientError: false
expectEvents:
- client: *client0
events:
- commandStartedEvent:
command:
aggregate: *collection0Name
pipeline: *pipeline2
let: *let2

0 comments on commit d270610

Please sign in to comment.