Add mocha based autotest for encfs module

This commit is contained in:
Johannes Zellner
2013-08-18 21:03:04 -07:00
parent 5c59a2f651
commit d25e48bfe2
4 changed files with 82 additions and 46 deletions
+14 -3
View File
@@ -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));
});
};
+5
View File
@@ -16,6 +16,11 @@
"dependencies": {
"mkdirp" : ""
},
"devDependencies": {
"mocha": "*",
"expect.js": "*"
},
"scripts": {
"test": "cd test; ../node_modules/mocha/bin/mocha -R spec;"
}
}
-43
View File
@@ -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!");
});
});
});
});
+63
View File
@@ -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();
});
});
});