Add mocha based autotest for encfs module
This commit is contained in:
+14
-3
@@ -3,6 +3,7 @@
|
||||
var assert = require("assert"),
|
||||
path = require("path"),
|
||||
mkdirp = require('mkdirp'),
|
||||
exec = require('child_process').exec,
|
||||
spawn = require("child_process").spawn;
|
||||
|
||||
exports = module.exports = {
|
||||
@@ -53,8 +54,6 @@ function createOrMount(root, password, callback) {
|
||||
|
||||
var args = ENCFS_CMD_ARGS.concat([absRootPath, absMountPoint]);
|
||||
|
||||
console.log(args);
|
||||
|
||||
// The callbackWrapper makes sure we only call back once!
|
||||
var calledBack = false;
|
||||
function callbackWrapper(error) {
|
||||
@@ -145,4 +144,16 @@ Root.prototype.unmount = function(callback) {
|
||||
|
||||
Root.prototype.info = function(callback) {
|
||||
assert(typeof callback === "function", "1 argument must be a callback function");
|
||||
};
|
||||
};
|
||||
|
||||
Root.prototype.isMounted = function(callback) {
|
||||
var that = this;
|
||||
|
||||
exec('mount', {}, function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
return callback(null, (stdout.indexOf(that.mountPoint) >= 0));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
"dependencies": {
|
||||
"mkdirp" : ""
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "*",
|
||||
"expect.js": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "cd test; ../node_modules/mocha/bin/mocha -R spec;"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
"use strict";
|
||||
|
||||
var encfs = require("./index.js");
|
||||
|
||||
encfs.create("test_root", "test_mnt", "foobar1337", function (error, result) {
|
||||
if (error) {
|
||||
console.log("Creating volume failed:", error);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Volume created:", result);
|
||||
|
||||
result.unmount(function (error) {
|
||||
if (error) {
|
||||
console.log("Unable to unmount:", error);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Unmount succeeded");
|
||||
console.log("Now try to mount and unmount again.");
|
||||
|
||||
result.mount("foobar1337", function (error) {
|
||||
if (error) {
|
||||
console.log("Unable to mount:", error);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Mount succeeded");
|
||||
|
||||
result.unmount(function (error) {
|
||||
if (error) {
|
||||
console.log("Unable to unmount:", error);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Unmount succeeded");
|
||||
console.log("Done!");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
|
||||
var encfs = require('../index.js'),
|
||||
async = require('async');
|
||||
|
||||
var assert = require('assert');
|
||||
var expect = require('expect.js');
|
||||
|
||||
describe('encfs', function () {
|
||||
var volume;
|
||||
|
||||
it('create volume', function (done) {
|
||||
encfs.create('test_root', 'test_mnt', 'foobar1337', function (error, result) {
|
||||
expect(error).to.not.be.ok();
|
||||
expect(result).to.be.ok();
|
||||
|
||||
volume = result;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('check volume is mounted', function (done) {
|
||||
volume.isMounted(function (error, result) {
|
||||
expect(error).to.not.be.ok();
|
||||
expect(result).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('unmount volume', function (done) {
|
||||
volume.unmount(function (error) {
|
||||
expect(error).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('check volume is unmounted', function (done) {
|
||||
volume.isMounted(function (error, result) {
|
||||
expect(error).to.not.be.ok();
|
||||
expect(result).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('mount volume', function (done) {
|
||||
volume.mount('foobar1337', function (error) {
|
||||
expect(error).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('unmount volume', function (done) {
|
||||
volume.unmount(function (error) {
|
||||
expect(error).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user