-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
used latest version of mongodb for tests bec of npm audit vulnerabili…
…ty (#100) * used latest version of mongodb for tests bec of vulnerability * closed mongo connection * used correct mongo connection string. * removed console
- Loading branch information
Showing
4 changed files
with
80 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
var Promise = require('bluebird'), | ||
mongo = require('mongodb'), | ||
data = require('../data'); | ||
|
||
|
||
Promise.promisifyAll(mongo); | ||
Promise.promisifyAll(mongo.MongoClient); | ||
|
||
module.exports = () => ({ | ||
db : mongo.connectAsync('mongodb://mongodb:27017/etl_tests'), | ||
|
||
getCollection : function(name) { | ||
var self = this,collection; | ||
|
||
if (this.collections[name]) | ||
return Promise.resolve(this.collections[name]); | ||
|
||
return this.db | ||
.then(function(db) { | ||
return db.collection(name); | ||
}) | ||
.then(function(d) { | ||
collection = self.collections[name] = d; | ||
return collection.removeAsync({}); | ||
}) | ||
.then(function() { | ||
return collection; | ||
}); | ||
}, | ||
|
||
collections: {}, | ||
|
||
cleanup : function() { | ||
return this.db | ||
.then(function(db) { | ||
return Promise.map(Object.keys(this.collections),function(key) { | ||
return db.dropCollectionAsync(key); | ||
}); | ||
}); | ||
|
||
const mongodbClient = require("mongodb").MongoClient; | ||
|
||
let client; | ||
|
||
async function getMongodbDriver() { | ||
|
||
if (!client) { | ||
client = await mongodbClient.connect('mongodb://mongodb:27017/etl_tests', {"useNewUrlParser": true, "useUnifiedTopology": true}); | ||
} | ||
}); | ||
|
||
return client.db(); | ||
} | ||
|
||
async function getCollection(collectionName) { | ||
const db = await getMongodbDriver(); | ||
return db.collection(collectionName); | ||
} | ||
|
||
async function clear() { | ||
const db = await getMongodbDriver(); | ||
await Promise.all( | ||
[ | ||
db.collection("insert").deleteMany({}), | ||
db.collection("update-empty").deleteMany({}), | ||
db.collection("update-populated").deleteMany({}), | ||
db.collection("upsert").deleteMany({}), | ||
db.collection("upsert2").deleteMany({}), | ||
db.collection("upsert3").deleteMany({}) | ||
]); | ||
await client.close(); | ||
} | ||
|
||
module.exports = { | ||
getCollection, | ||
clear | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters