Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
Merge af76e77 into b967c61
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Jun 8, 2017
2 parents b967c61 + af76e77 commit b9230ec
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
35 changes: 34 additions & 1 deletion src/IpfsConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,6 @@ export class IpfsConnector extends EventEmitter {
return this.staticGetPorts();
}


/**
*
* @param ports
Expand Down Expand Up @@ -737,4 +736,38 @@ export class IpfsConnector extends EventEmitter {
}
);
}

/**
* Run a raw command through the command line on the local daemon.
* @param args
* @returns {Bluebird<U>}
*/
public runCommand(args: string) {
return this.checkExecutable()
.then((execPath) => {
return new Promise((resolve, reject) => {
let stdout = '';
let stderr = '';
const command = childProcess.spawn(execPath, [args],
{env: this.options.extra.env}
);
command.stdout.on('data', (data) => {
stdout += data;
});
command.stderr.on('data', (data) => {
stderr += data;
});
command.on('close', (code) => {
if (code !== 0) {
this.logger.error(stderr);
return reject(stderr);
}
if (stderr) {
this.logger.warn(stderr);
}
return resolve(stdout);
});
});
});
}
}
21 changes: 20 additions & 1 deletion tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ describe('IpfsConnector', function () {
});
});

it('run raw cli commands', function () {
return instance.runCommand('id')
.then((stdout: string) => {
expect(stdout).to.exist;
})
.catch(() => {
throw new Error('Should not fail');
});
});

it('fail running a raw cli commands properly', function () {
return instance.runCommand('doesnotexist')
.then(() => {
throw new Error('Should not succed');
})
.catch((stderr: string) => {
expect(stderr).to.exist;
});
});

it('doesn`t throw when calling multiple start', function () {
return IpfsConnector.getInstance().start().then(() => IpfsConnector.getInstance().start());
});
Expand All @@ -335,7 +355,6 @@ describe('IpfsConnector', function () {
instance.downloadManager.deleteBin().then(() => done());
});


after(function (done) {
instance.stop().then(() => {
rimraf(binTarget, function () {
Expand Down

0 comments on commit b9230ec

Please sign in to comment.