volumes: async'ify
This commit is contained in:
@@ -6,10 +6,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
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' };
|
||||
@@ -32,82 +33,60 @@ function cleanup(done) {
|
||||
describe('Volumes', function () {
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
it('cannot add bad name', async function () {
|
||||
const [error] = await safe(volumes.add('music/is', '/tmp/music', 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('music', '/tmp/music', AUDIT_SOURCE));
|
||||
if (!error) throw new Error('Expecting bad field error');
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
let volume;
|
||||
|
||||
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('can add volume', async function () {
|
||||
const id = await volumes.add('music', '/mnt/cloudron-test-music', AUDIT_SOURCE);
|
||||
expect(id).to.be.a('string');
|
||||
volume = { id, name: 'music', hostPath: '/mnt/cloudron-test-music' };
|
||||
});
|
||||
|
||||
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('cannot add duplicate path', async function () {
|
||||
const [error] = await safe(volumes.add('music-dup', '/mnt/cloudron-test-music', AUDIT_SOURCE));
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
});
|
||||
|
||||
it('can add volume', function (done) {
|
||||
volumes.add('music', '/mnt/cloudron-test-music', AUDIT_SOURCE, function (error, id) {
|
||||
expect(error).to.be(null);
|
||||
expect(id).to.be.a('string');
|
||||
volume = { id, name: 'music', hostPath: '/mnt/cloudron-test-music' };
|
||||
done();
|
||||
});
|
||||
it('cannot add duplicate name', async function () {
|
||||
const [error] = await safe(volumes.add('music', '/media/cloudron-test-music', AUDIT_SOURCE));
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
});
|
||||
|
||||
it('cannot add duplicate path', function (done) {
|
||||
volumes.add('music-dup', '/mnt/cloudron-test-music', AUDIT_SOURCE, function (error) {
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
done();
|
||||
});
|
||||
it('can get volume', async function () {
|
||||
const result = await volumes.get(volume.id);
|
||||
expect(result.hostPath).to.be('/mnt/cloudron-test-music');
|
||||
});
|
||||
|
||||
it('cannot add duplicate name', function (done) {
|
||||
volumes.add('music', '/media/cloudron-test-music', AUDIT_SOURCE, function (error) {
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
done();
|
||||
});
|
||||
it('cannot get random volume', async function () {
|
||||
const result = await volumes.get('randomvolume');
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('can get volume', function (done) {
|
||||
volumes.get(volume.id, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result.hostPath).to.be('/mnt/cloudron-test-music');
|
||||
done();
|
||||
});
|
||||
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 get random volume', function (done) {
|
||||
volumes.get('randomvolume', function (error) {
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
done();
|
||||
});
|
||||
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 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);
|
||||
expect(result[0].id).to.be(volume.id);
|
||||
expect(result[0].hostPath).to.be('/mnt/cloudron-test-music');
|
||||
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) {
|
||||
volumes.del(volume, AUDIT_SOURCE, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('can del volume', async function () {
|
||||
await volumes.del(volume, AUDIT_SOURCE);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user