0
Fork 0
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:
Juan Picado @jotadeveloper 2017-08-25 21:16:55 +02:00
parent e4f7f32f91
commit 2c3a8f9d42
No known key found for this signature in database
GPG key ID: 18AC54485952D158
3 changed files with 39 additions and 0 deletions

View 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/));
});
});
});

View file

@ -0,0 +1 @@
{"list"[],"secret":"14705eeaed167749990dafa07f908d2a9504bfdb0f6ca4102eed5acba0bc9076"}

View file

@ -0,0 +1 @@
{"list":["@verdaccio/test"],"secret":"48cd053de97d4ef34aea4f1efb902334442bea1e735df5fdc9424c986a281b3d"}