Files
cloudron-box/src/test/volumes-test.js
Girish Ramakrishnan c7474511aa fix volume test
2021-05-17 16:23:37 -07:00

93 lines
3.2 KiB
JavaScript

/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
const async = require('async'),
BoxError = require('../boxerror.js'),
database = require('../database.js'),
expect = require('expect.js'),
safe = require('safetydance'),
volumes = require('../volumes.js');
const AUDIT_SOURCE = { ip: '1.2.3.4', userId: 'someuserid' };
function setup(done) {
// ensure data/config/mount paths
async.series([
database.initialize,
database._clear
], done);
}
function cleanup(done) {
async.series([
database._clear,
database.uninitialize
], done);
}
describe('Volumes', function () {
before(setup);
after(cleanup);
it('cannot add bad name', async function () {
const [error] = await safe(volumes.add({ name: 'music/is', hostPath: '/tmp/music', mountType: 'noop', mountOptions: {} }, AUDIT_SOURCE));
if (!error) throw new Error('Expecting bad field error');
expect(error.reason).to.be(BoxError.BAD_FIELD);
});
it('cannot add bad path', async function () {
const [error] = await safe(volumes.add({ name: 'music', hostPath: '/tmp/music', mountType: 'noop', mountOptions: {} }, AUDIT_SOURCE));
if (!error) throw new Error('Expecting bad field error');
expect(error.reason).to.be(BoxError.BAD_FIELD);
});
let volume;
it('can add volume', async function () {
const id = await volumes.add({ name: 'music', hostPath: '/mnt/cloudron-test-music', mountType: 'noop', mountOptions: {} }, AUDIT_SOURCE);
expect(id).to.be.a('string');
volume = { id, name: 'music', hostPath: '/mnt/cloudron-test-music' };
});
it('cannot add duplicate path', async function () {
const [error] = await safe(volumes.add({ name: 'music-dup', hostPath: '/mnt/cloudron-test-music', mountType: 'noop', mountOptions: {} }, AUDIT_SOURCE));
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
});
it('cannot add duplicate name', async function () {
const [error] = await safe(volumes.add({ name: 'music', hostPath: '/mnt/cloudron-test-music2', mountType: 'noop', mountOptions: {} }, AUDIT_SOURCE));
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
});
it('can get volume', async function () {
const result = await volumes.get(volume.id);
expect(result.hostPath).to.be('/mnt/cloudron-test-music');
});
it('cannot get random volume', async function () {
const result = await volumes.get('randomvolume');
expect(result).to.be(null);
});
it('can list volumes', async function () {
const result = await volumes.list();
expect(result).to.be.an(Array);
expect(result.length).to.be(1);
expect(result[0].id).to.be(volume.id);
expect(result[0].hostPath).to.be('/mnt/cloudron-test-music');
});
it('cannot del random volume', async function () {
const [error] = await safe(volumes.del({ id: 'randomvolume' }, AUDIT_SOURCE));
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
it('can del volume', async function () {
await volumes.del(volume, AUDIT_SOURCE);
});
});