init
This commit is contained in:
50
lib/modules/test/fakedb.js
Normal file
50
lib/modules/test/fakedb.js
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Implements a fake db for testing
|
||||
//
|
||||
class FakeDB {
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
constructor(data) {
|
||||
this.data = data
|
||||
this.fetch = this.fetch.bind(this)
|
||||
this.pipe = this.pipe.bind(this)
|
||||
}
|
||||
|
||||
//
|
||||
// Simulate a db connection by just returning
|
||||
// a promise
|
||||
//
|
||||
connect() {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
//
|
||||
// Returns all results in one batch
|
||||
//
|
||||
fetch() {
|
||||
return Promise.resolve({
|
||||
recordset: this.data
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
// Delivers results to the specified write
|
||||
// stream
|
||||
//
|
||||
pipe(query, writable) {
|
||||
|
||||
this.data.forEach(function(record) {
|
||||
writable.write(record)
|
||||
})
|
||||
|
||||
writable.end()
|
||||
|
||||
return writable
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Export the class
|
||||
//
|
||||
module.exports = FakeDB
|
||||
Reference in New Issue
Block a user