Add tests and fixes for applyPatches()
This commit is contained in:
Родитель
64fe490a93
Коммит
e023674b69
2
index.js
2
index.js
|
@ -204,7 +204,7 @@ function checkAllPatchesAvailable(callback) {
|
|||
function applyPatches(callback) {
|
||||
var ctx = this
|
||||
|
||||
async.each(
|
||||
async.eachSeries(
|
||||
ctx.patchesToApply,
|
||||
function(patch, donePatch) {
|
||||
// emit : 'Updating DB for patch ' + patch.from + ' to ' + patch.to
|
||||
|
|
|
@ -116,7 +116,6 @@ test('check all patches are available (fails, no patch #2)', function(t) {
|
|||
|
||||
t.end()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
test('check all patches are available (fails, no patch #1)', function(t) {
|
||||
|
@ -139,5 +138,50 @@ test('check all patches are available (fails, no patch #1)', function(t) {
|
|||
|
||||
t.end()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
test('checking that these patch files are executed', function(t) {
|
||||
var count = 0
|
||||
var ctx = {
|
||||
connection : {
|
||||
query : function(sql, callback) {
|
||||
t.equal(sql, ctx.patchesToApply[count].sql, 'SQL is correct')
|
||||
count += 1
|
||||
callback()
|
||||
},
|
||||
},
|
||||
patchesToApply : [
|
||||
{ sql : '-- 0->1' },
|
||||
{ sql : '-- 1->2' },
|
||||
{ sql : '-- 2->3' },
|
||||
],
|
||||
}
|
||||
|
||||
patcher.applyPatches.call(ctx, function(err) {
|
||||
t.ok(!err, 'No error occurred')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('checking that an error comes back if the query fails', function(t) {
|
||||
t.plan(3)
|
||||
|
||||
var count = 0
|
||||
var ctx = {
|
||||
connection : {
|
||||
query : function(sql, callback) {
|
||||
t.equal(sql, '-- 0->1', 'The sql is what is expected')
|
||||
callback(new Error('Something went wrong'))
|
||||
},
|
||||
},
|
||||
patchesToApply : [
|
||||
{ sql : '-- 0->1' },
|
||||
],
|
||||
}
|
||||
|
||||
patcher.applyPatches.call(ctx, function(err) {
|
||||
t.ok(err, 'An error occurred')
|
||||
t.equal(err.message, 'Something went wrong', 'The message is correct')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче