Add test for 4.0 → 5.0 DB upgrade

With a mechanism for specifying a zipped DB copy to use as the initial
DB when resetting the DB in tests
This commit is contained in:
Dan Stillman 2021-08-16 19:50:44 -04:00
parent 0f96c20f3c
commit eac98d1c2e
3 changed files with 33 additions and 2 deletions

View file

@ -624,8 +624,19 @@ async function resetDB(options = {}) {
var db = Zotero.DataDirectory.getDatabase();
await Zotero.reinit(
async function () {
// Swap in the initial copy we made of the DB
await OS.File.copy(db + '-test-template', db);
// Extract a zipped DB file into place as the initial DB
if (options.dbFile && options.dbFile.endsWith('.zip')) {
let zipReader = Components.classes['@mozilla.org/libjar/zip-reader;1']
.createInstance(Components.interfaces.nsIZipReader);
zipReader.open(Zotero.File.pathToFile(options.dbFile));
zipReader.extract('zotero.sqlite', Zotero.File.pathToFile(db));
zipReader.close();
}
// Otherwise swap in the initial copy we made of the DB, or an alternative non-zip file
// if given
else {
await OS.File.copy(options.dbFile || db + '-test-template', db);
}
_defaultGroup = null;
},
false,