Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';
import { expect } from 'chai';
import * as sinon from 'sinon';

const { expect } = require('chai');
const sinon = require('sinon');
const { Topology } = require('../../mongodb');
import { Topology } from '../../../src/sdam/topology';

describe('URI', function () {
let client;
Expand All @@ -20,31 +19,23 @@ describe('URI', function () {
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single' } },

test: function (done) {
var self = this;

test: async function () {
const authInformation = process.env.AUTH === 'auth' ? 'bob:pwd123@' : '';
// Connect using the connection string
const client = this.configuration.newClient(
`mongodb://${authInformation}localhost:27017/?w=0`
);

client.connect(function (err, client) {
expect(err).to.not.exist;
var db = client.db(self.configuration.db);

db.collection('mongoclient_test').update(
{ a: 1 },
{ $set: { b: 1 } },
{ upsert: true },
function (err, result) {
expect(err).to.not.exist;
expect(result).to.exist;
expect(result).property('acknowledged').to.be.false;
client.close(done);
}
);
});
await client.connect();
const db = client.db(this.configuration.db);

const result = await db
.collection('mongoclient_test')
.updateOne({ a: 1 }, { $set: { b: 1 } }, { upsert: true });

expect(result).to.exist;
expect(result).property('acknowledged').to.be.false;
await client.close();
}
});

Expand All @@ -53,17 +44,15 @@ describe('URI', function () {
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single' } },

test: function (done) {
test: async function () {
if (process.platform === 'win32') {
return done();
return;
}

const client = this.configuration.newClient('mongodb://%2Ftmp%2Fmongodb-27017.sock');

client.connect(function (err, client) {
expect(err).to.not.exist;
client.close(done);
});
await client.connect();
const err = await client.close().catch(e => e);
expect(err).to.not.exist;
}
});

Expand All @@ -72,13 +61,12 @@ describe('URI', function () {
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: { requires: { topology: 'single' } },

test: function (done) {
test: async function () {
const client = this.configuration.newClient('mongodb://127.0.0.1:27017/?fsync=true');
client.connect((err, client) => {
var db = client.db(this.configuration.db);
expect(db.writeConcern.journal).to.be.true;
client.close(done);
});
await client.connect();
const db = client.db(this.configuration.db);
expect(db.writeConcern.journal).to.be.true;
await client.close();
}
});

Expand Down Expand Up @@ -114,17 +102,15 @@ describe('URI', function () {

it('should correctly translate uri options', {
metadata: { requires: { topology: 'replicaset' } },
test: function (done) {
test: async function () {
const config = this.configuration;
const uri = `mongodb://${config.host}:${config.port}/${config.db}?replicaSet=${config.replicasetName}`;

const client = this.configuration.newClient(uri);
client.connect((err, client) => {
expect(err).to.not.exist;
expect(client).to.exist;
expect(client.options.replicaSet).to.exist.and.equal(config.replicasetName);
client.close(done);
});
await client.connect();
expect(client).to.exist;
expect(client.options.replicaSet).to.exist.and.equal(config.replicasetName);
await client.close();
}
});

Expand All @@ -136,7 +122,7 @@ describe('URI', function () {
expect(options.credentials.mechanism).to.eql('MONGODB-X509');

connectStub.restore();
return;
return undefined;
}

const topologyPrototype = Topology.prototype;
Expand Down