Skip to content

Commit

Permalink
data missing
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Apr 6, 2020
1 parent d81c7bc commit 3141096
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
6 changes: 2 additions & 4 deletions lib/firecracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ Firecracker.prototype.spawn = function (binPath) {
binPath = binPath || '/usr/bin/firecracker';

return new Promise(function (resolve, reject) {

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

self.child.on('exit', function (code, signal) {
Expand All @@ -300,10 +299,9 @@ Firecracker.prototype.spawn = function (binPath) {

Firecracker.prototype.kill = function () {
var killed = this.child.kill();
console.log(killed);
if(killed === true) {
fs.unlink(self.options.socketPath, () => { });
self.child = undefined;
fs.unlink(this.options.socketPath, () => { });
this.child = undefined;
}
return killed;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/machineconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MachineConfig.prototype.get = function (callback) {
}
};

MachineConfig.prototype.update = function (callback) {
MachineConfig.prototype.update = function (data, callback) {
var self = this;
if (!callback && typeof opts === 'function') {
callback = opts;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "firecrackerode",
"description": "Firecracker API module.",
"version": "1.0.1",
"version": "1.0.2",
"author": "Pedro Dias <[email protected]>",
"maintainers": [
"apocas <[email protected]>"
Expand Down
42 changes: 36 additions & 6 deletions test/firefracker.js → test/firecracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ const os = require('os');
const expect = require('chai').expect;
var firecracker = require('./helper').firecracker;

before(async () => {
before(async () => {
try {
let process = await firecracker.spawn();
console.log('Firefracker started! ' + process.pid);
} catch (err) {
expect(err).to.be.null;
}
});

after(function() {
after(function () {
var killed = firecracker.kill();
expect(killed).to.be.true;
});
Expand All @@ -28,8 +27,8 @@ describe('#firecracker', function () {
await firecracker.downloadImage(rootImg, os.tmpdir() + '/hello-rootfs.ext4');
}
catch (err) {
expect(err).satisfy(function(value) {
if(value === null || value == 'File already exists') {
expect(err).satisfy(function (value) {
if (value === null || value == 'File already exists') {
return true;
} else {
return false;
Expand Down Expand Up @@ -65,7 +64,7 @@ describe('#firecracker', function () {
});
});

describe('#firestarter', function () {
describe('#firecracker', function () {
it('should get info', async function () {
try {
const data = await firecracker.info();
Expand All @@ -90,4 +89,35 @@ describe('#firecracker', function () {
});
});

describe('#machine-config', function () {
it('should get machine-config', async function () {
try {
var machineConfig = firecracker.machineConfig();
const data = await machineConfig.get();
expect(data).to.be.ok;
expect(data.vcpu_count).to.equal(1);
expect(data.mem_size_mib).to.equal(128);
}
catch (err) {
expect(err).to.be.null;
}
});

it('should partially update machine-config', async function () {
try {
firecracker.kill();
await firecracker.spawn();
var machineConfig = firecracker.machineConfig();
await machineConfig.partialUpdate({ 'mem_size_mib': 256 });
var machineConfig = firecracker.machineConfig();
let data = await machineConfig.get();
expect(data).to.be.ok;
expect(data.vcpu_count).to.equal(1);
expect(data.mem_size_mib).to.equal(256);
}
catch (err) {
expect(err).to.be.null;
}
});
});
});

0 comments on commit 3141096

Please sign in to comment.