Files
cloudron-box/src/test/volumes-test.js
T

114 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-10-27 22:39:05 -07:00
/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
var async = require('async'),
BoxError = require('../boxerror.js'),
database = require('../database.js'),
expect = require('expect.js'),
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);
2020-10-28 15:51:43 -07:00
let volume;
2020-10-27 22:39:05 -07:00
it('cannot add bad name', function (done) {
volumes.add('music/is', '/tmp/music', AUDIT_SOURCE, function (error) {
expect(error.reason).to.be(BoxError.BAD_FIELD);
done();
});
});
it('cannot add bad path', function (done) {
volumes.add('music', '/tmp/music', AUDIT_SOURCE, function (error) {
expect(error.reason).to.be(BoxError.BAD_FIELD);
done();
});
});
it('can add volume', function (done) {
volumes.add('music', '/mnt/cloudron-test-music', AUDIT_SOURCE, function (error, id) {
2020-10-27 22:39:05 -07:00
expect(error).to.be(null);
expect(id).to.be.a('string');
volume = { id, name: 'music', hostPath: '/mnt/cloudron-test-music' };
2020-10-27 22:39:05 -07:00
done();
});
});
it('cannot add duplicate path', function (done) {
volumes.add('music-dup', '/mnt/cloudron-test-music', AUDIT_SOURCE, function (error) {
2020-10-27 22:39:05 -07:00
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
done();
});
});
it('cannot add duplicate name', function (done) {
volumes.add('music', '/media/cloudron-test-music', AUDIT_SOURCE, function (error) {
2020-10-27 22:39:05 -07:00
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
done();
});
});
it('can get volume', function (done) {
2020-10-28 15:51:43 -07:00
volumes.get(volume.id, function (error, result) {
2020-10-27 22:39:05 -07:00
expect(error).to.be(null);
expect(result.hostPath).to.be('/mnt/cloudron-test-music');
2020-10-27 22:39:05 -07:00
done();
});
});
it('cannot get random volume', function (done) {
volumes.get('randomvolume', function (error) {
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
it('can list volumes', function (done) {
volumes.list(function (error, result) {
expect(error).to.be(null);
expect(result).to.be.an(Array);
expect(result.length).to.be(1);
2020-10-28 15:51:43 -07:00
expect(result[0].id).to.be(volume.id);
expect(result[0].hostPath).to.be('/mnt/cloudron-test-music');
2020-10-27 22:39:05 -07:00
done();
});
});
it('cannot del random volume', function (done) {
volumes.get('randomvolume', function (error) {
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
it('can del volume', function (done) {
2020-10-28 15:51:43 -07:00
volumes.del(volume, AUDIT_SOURCE, function (error) {
2020-10-27 22:39:05 -07:00
expect(error).to.be(null);
done();
});
});
2020-12-23 15:34:23 -08:00
});