mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
test: Add unit test for a scenario when the database is corrupted
This commit is contained in:
parent
e4f7f32f91
commit
2c3a8f9d42
3 changed files with 39 additions and 0 deletions
37
test/unit/local-data.spec.js
Normal file
37
test/unit/local-data.spec.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const LocalData = require('../../src/lib/storage/local/local-data');
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
|
||||
|
||||
describe('Local Database', function() {
|
||||
|
||||
|
||||
describe('reading database', () => {
|
||||
|
||||
const buildCorruptedPath = () => path.join(__dirname, './partials/storage/verdaccio-corrupted.db.json');
|
||||
|
||||
it('should return empty database on read corrupted database', () => {
|
||||
const config = new LocalData(buildCorruptedPath());
|
||||
assert(_.isEmpty(config.data.list));
|
||||
});
|
||||
|
||||
it('should return a database on read valid database', () => {
|
||||
const config = new LocalData(path.join(__dirname, './partials/storage/verdaccio.db.json'));
|
||||
assert(_.isEmpty(config.data.list) === false);
|
||||
});
|
||||
|
||||
it('should fails on sync a corrupted database', () => {
|
||||
const config = new LocalData(buildCorruptedPath());
|
||||
const error = config.sync();
|
||||
|
||||
assert(_.isError(error));
|
||||
assert(error.message.match(/locked/));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
1
test/unit/partials/storage/verdaccio-corrupted.db.json
Normal file
1
test/unit/partials/storage/verdaccio-corrupted.db.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"list"[],"secret":"14705eeaed167749990dafa07f908d2a9504bfdb0f6ca4102eed5acba0bc9076"}
|
1
test/unit/partials/storage/verdaccio.db.json
Normal file
1
test/unit/partials/storage/verdaccio.db.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"list":["@verdaccio/test"],"secret":"48cd053de97d4ef34aea4f1efb902334442bea1e735df5fdc9424c986a281b3d"}
|
Loading…
Reference in a new issue