Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Apr 5, 2020
1 parent fb39863 commit d81c7bc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/firecracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,25 +278,34 @@ Firecracker.prototype.spawn = function (binPath) {

return new Promise(function (resolve, reject) {

self.child = child_process.spawn(binPath, ['--api-sock', self.options.socketPath]);
self.child = child_process.spawn(binPath, ['--api-sock', self.options.socketPath], { detached: true });

self.child.on('exit', function (code, signal) {
fs.unlink(self.options.socketPath, () => { });
self.child = undefined;
});

self.child.on('close', function (code, signal) {
fs.unlink(self.options.socketPath, () => { });
self.child = undefined;
});

self.child.on('error', function (err) {
fs.unlink(self.options.socketPath, () => { });
});

resolve(self.child);
});
};

Firecracker.prototype.kill = function () {
if (this.child) {
this.child.kill();
var killed = this.child.kill();
console.log(killed);
if(killed === true) {
fs.unlink(self.options.socketPath, () => { });
self.child = undefined;
}
return killed;
};

module.exports = Firecracker;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"main": "./lib/firecracker",
"scripts": {
"test": "./node_modules/mocha/bin/mocha -R spec --timeout 10000 --exit "
"test": "./node_modules/mocha/bin/mocha -R spec --timeout 10000"
},
"license": "Apache-2.0",
"engines": {
Expand Down
13 changes: 12 additions & 1 deletion test/firefracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ before(async () => {
}
});

after(function() {
var killed = firecracker.kill();
expect(killed).to.be.true;
});

describe('#firecracker', function () {

describe('#images', function () {
Expand All @@ -23,7 +28,13 @@ describe('#firecracker', function () {
await firecracker.downloadImage(rootImg, os.tmpdir() + '/hello-rootfs.ext4');
}
catch (err) {
expect(err).to.be.null;
expect(err).satisfy(function(value) {
if(value === null || value == 'File already exists') {
return true;
} else {
return false;
}
});
}
});

Expand Down

0 comments on commit d81c7bc

Please sign in to comment.