Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
feat: add start param in getSerialPortOutput options (#507)
Browse files Browse the repository at this point in the history
* feat: added start param in options
  • Loading branch information
laljikanjareeya committed Oct 15, 2020
1 parent 2de8106 commit de3ecd4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ class VM extends common.ServiceObject {
*
* @param {number=} port - The port from which the output is retrieved (1-4).
* Default: `1`.
* @param {object=} options - Configuration object.
* @param {string=} options.start - The starting byte position of the output to return.
* To start with the first byte of output to the specified port, omit this field or set it to 0.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {object} callback.output - The output from the port.
Expand All @@ -494,15 +497,27 @@ class VM extends common.ServiceObject {
* const apiResponse = data[1];
* });
*/
getSerialPortOutput(port, callback) {
if (is.fn(port)) {
getSerialPortOutput(port, options, callback) {
if (is.object(port)) {
options = port;
port = 1;
} else if (is.fn(port)) {
callback = port;
port = 1;
}

if (is.fn(options)) {
callback = options;
options = {};
}

port = port || 1;
options = options || {};
const reqOpts = {
uri: '/serialPort',
qs: {
port: port,
start: options.start || 0,
},
};
const request = common.ServiceObject.prototype.request;
Expand Down
13 changes: 12 additions & 1 deletion test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ describe('VM', () => {
});

describe('getSerialPortOutput', () => {
const EXPECTED_QUERY = {port: 1};
const EXPECTED_QUERY = {port: 1, start: 0};

it('should default to port 1', done => {
FakeServiceObject.prototype.request = function (reqOpts) {
Expand All @@ -406,6 +406,17 @@ describe('VM', () => {
vm.getSerialPortOutput(port, assert.ifError);
});

it('should override the start', done => {
const start = 10;

FakeServiceObject.prototype.request = function (reqOpts) {
assert.strictEqual(reqOpts.qs.start, start);
done();
};

vm.getSerialPortOutput({start}, assert.ifError);
});

it('should make the correct API request', done => {
FakeServiceObject.prototype.request = function (reqOpts) {
assert.strictEqual(reqOpts.uri, '/serialPort');
Expand Down

0 comments on commit de3ecd4

Please sign in to comment.