Skip to content

Commit

Permalink
t2: add missing help to crash-reporter (shows status). Fixes gh-708 (#…
Browse files Browse the repository at this point in the history
…713)

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Apr 27, 2016
1 parent bc23cca commit 41de6c8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 25 deletions.
21 changes: 10 additions & 11 deletions bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,24 @@ parser.command('install-drivers')

parser.command('crash-reporter')
.callback(opts => {
var cr = Promise.resolve();

// t2 crash-reporter --on
if (opts.on) {
return CrashReporter.on().then(() => {
// t2 crash-reporter --on --test
if (opts.test) {
CrashReporter.test().then(module.exports.closeSuccessfulCommand);
}
}).then(module.exports.closeSuccessfulCommand, module.exports.closeFailedCommand);
cr = CrashReporter.on();
} else if (opts.off) {
// t2 crash-reporter --on
return CrashReporter.off()
.then(module.exports.closeSuccessfulCommand, module.exports.closeFailedCommand);
// t2 crash-reporter --off
cr = CrashReporter.off();
}

// t2 crash-reporter --test
if (opts.test) {
// not handling failures, as we want to trigger a crash
CrashReporter.test()
cr.then(CrashReporter.test)
.then(module.exports.closeSuccessfulCommand);
} else {
cr.then(CrashReporter.status)
.then(module.exports.closeSuccessfulCommand, module.exports.closeFailedCommand);
}
})
.option('off', {
Expand All @@ -116,7 +115,7 @@ parser.command('crash-reporter')
flag: true,
help: 'Test the Crash Reporter.'
})
.help('Crash Reporter enable/disable');
.help('Configure the Crash Reporter.');

parser.command('provision')
.callback(callControllerCallback('provisionTessel'))
Expand Down
7 changes: 7 additions & 0 deletions lib/crash-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ CrashReporter.post = function(labels, report) {
});
};

CrashReporter.status = () => {
return Preferences.load().then(prefs => {
logs.info(`Crash Reporter is ${prefs[CRASH_REPORTER_PREFERENCE].toUpperCase()}`);
});
};


CrashReporter.test = () => {
return Promise.reject(new Error('Testing the crash reporter'));
};
Expand Down
44 changes: 30 additions & 14 deletions test/unit/bin-tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ exports['Tessel (cli: crash-reporter)'] = {
this.crOn = this.sandbox.stub(CrashReporter, 'on').returns(Promise.resolve());
this.crOff = this.sandbox.stub(CrashReporter, 'off').returns(Promise.resolve());
this.crPost = this.sandbox.stub(CrashReporter, 'post').returns(Promise.resolve());
this.crStatus = this.sandbox.stub(CrashReporter, 'status').returns(Promise.resolve());
this.crSubmit = this.sandbox.stub(CrashReporter, 'submit').returns(Promise.resolve());
this.crTest = this.sandbox.stub(CrashReporter, 'test').returns(Promise.resolve());

Expand All @@ -759,59 +760,71 @@ exports['Tessel (cli: crash-reporter)'] = {
},

callThroughNoOptions: function(test) {
test.expect(3);
test.expect(4);

var resolve = Promise.resolve();
this.crStatus.restore();
this.crStatus = this.sandbox.stub(CrashReporter, 'status').returns(resolve);

cli(['crash-reporter']);

test.equal(this.crOn.callCount, 0);
test.equal(this.crOff.callCount, 0);
test.equal(this.crTest.callCount, 0);


test.done();
resolve.then(() => {
test.equal(this.crStatus.callCount, 1);
test.done();
});
},

on: function(test) {
test.expect(3);
test.expect(4);

cli(['crash-reporter', '--on=true']);

test.equal(this.crOn.callCount, 1);
test.equal(this.crOff.callCount, 0);
test.equal(this.crTest.callCount, 0);

test.equal(this.crStatus.callCount, 0);

test.done();
},

off: function(test) {
test.expect(3);
test.expect(4);

cli(['crash-reporter', '--off=true']);

test.equal(this.crOn.callCount, 0);
test.equal(this.crOff.callCount, 1);
test.equal(this.crTest.callCount, 0);

test.equal(this.crStatus.callCount, 0);

test.done();
},

test: function(test) {
test.expect(3);
test.expect(4);

var resolve = Promise.resolve();
this.crTest.restore();
this.crTest = this.sandbox.stub(CrashReporter, 'test').returns(resolve);

cli(['crash-reporter', '--test=true']);

test.equal(this.crOn.callCount, 0);
test.equal(this.crOff.callCount, 0);
test.equal(this.crTest.callCount, 1);

test.equal(this.crStatus.callCount, 0);

test.done();
resolve.then(() => {
test.equal(this.crTest.callCount, 1);
test.done();
});
},

onAndTest: function(test) {
test.expect(3);
test.expect(4);

var resolve = Promise.resolve();
this.crOn.restore();
Expand All @@ -823,13 +836,14 @@ exports['Tessel (cli: crash-reporter)'] = {
test.equal(this.crOn.callCount, 1);
test.equal(this.crOff.callCount, 0);
test.equal(this.crTest.callCount, 1);
test.equal(this.crStatus.callCount, 0);

test.done();
});
},

onNoTestThrough: function(test) {
test.expect(3);
test.expect(4);

var resolve = Promise.resolve();
this.crOn.restore();
Expand All @@ -841,13 +855,14 @@ exports['Tessel (cli: crash-reporter)'] = {
test.equal(this.crOn.callCount, 1);
test.equal(this.crOff.callCount, 0);
test.equal(this.crTest.callCount, 0);
test.equal(this.crStatus.callCount, 1);

test.done();
});
},

unsuccessful: function(test) {
test.expect(3);
test.expect(4);

var resolve = Promise.resolve();
this.crOn.restore();
Expand All @@ -859,6 +874,7 @@ exports['Tessel (cli: crash-reporter)'] = {
test.equal(this.crOn.callCount, 1);
test.equal(this.crOff.callCount, 0);
test.equal(this.crTest.callCount, 0);
test.equal(this.crStatus.callCount, 1);
test.done();
});
},
Expand Down
22 changes: 22 additions & 0 deletions test/unit/crash-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,27 @@ exports['CrashReporter.post'] = {
test.done();
});
},
};

exports['CrashReporter.status'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.logsInfo = this.sandbox.stub(logs, 'info');
this.crPost = this.sandbox.spy(CrashReporter, 'status');
done();
},

tearDown: function(done) {
this.sandbox.restore();
done();
},

status: function(test) {
test.expect(1);

CrashReporter.status().then(() => {
test.equal(this.logsInfo.callCount, 1);
test.done();
});
},
};

0 comments on commit 41de6c8

Please sign in to comment.