Skip to content

Commit d239332

Browse files
committed
added key option to cancel method
1 parent 31b0236 commit d239332

6 files changed

Lines changed: 36 additions & 11 deletions

File tree

lib/mapping.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ var options = {
2121
}
2222
},
2323
test: {
24-
'key': {
25-
name: 'key',
26-
key: 'k',
27-
api: 'k',
28-
param: 'api_key',
29-
info: 'API key (if assigned). Contact the WebPageTest server administrator for a key if required'
30-
},
3124
'location': {
3225
name: 'location',
3326
key: 'l',
@@ -536,6 +529,15 @@ var options = {
536529
invert: true,
537530
info: 'hide labels for requests (URL) [false]'
538531
}
532+
},
533+
'apikey': {
534+
'key': {
535+
name: 'key',
536+
key: 'k',
537+
api: 'k',
538+
param: 'api_key',
539+
info: 'API key (if assigned). Contact the WebPageTest server administrator for a key if required'
540+
}
539541
}
540542
};
541543

@@ -565,13 +567,14 @@ var commands = {
565567
'test': {
566568
name: 'runTest',
567569
param: 'url_or_script',
568-
options: [options.test, options.request, options.results],
570+
options: [options.apikey, options.test, options.request, options.results],
569571
info: 'run test',
570572
nokey: [options.results]
571573
},
572574
'cancel': {
573575
name: 'cancelTest',
574576
param: 'id',
577+
options: [options.apikey],
575578
info: 'cancel running/pending test'
576579
},
577580
'har': {

lib/webpagetest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,14 @@ function runTest(what, options, callback) {
399399
}
400400

401401
function cancelTest(id, options, callback) {
402+
var query = {test: id};
403+
402404
callback = callback || options;
403405
options = options === callback ? undefined : options;
404406

405-
return api.call(this, paths.cancel, callback, {test: id}, options);
407+
helper.setQuery(mapping.commands.cancel, options, query);
408+
409+
return api.call(this, paths.cancel, callback, query, options);
406410
}
407411

408412
function getPageSpeedData(id, options, callback) {

test/command-line-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ describe('WebPageTest Command Line', function() {
149149
});
150150
});
151151

152+
it('gets a cancel test with api key input returns the API url', function(done) {
153+
exec(mock('cancel -k 12345 120816_V2_2'), function(err, data) {
154+
if (err) return done(err);
155+
data = JSON.parse(data);
156+
assert.equal(data.url, wptServer + 'cancelTest.php?test=120816_V2_2&k=12345');
157+
done();
158+
});
159+
});
160+
152161
it('gets a page speed data input returns the API url', function(done) {
153162
exec(mock('pagespeed 120816_V2_2'), function(err, data) {
154163
if (err) return done(err);

test/dryrun-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ describe('Dry Run', function() {
162162
});
163163
});
164164

165+
it('gets a cancel test with api key request', function(done) {
166+
wpt.cancelTest('120816_V2_2', {key: '12345', dryRun: true}, function (err, data) {
167+
if (err) return done(err);
168+
assert.equal(data.url, wptServer + 'cancelTest.php?test=120816_V2_2&k=12345');
169+
done();
170+
});
171+
});
172+
165173
it('gets page speed data request', function(done) {
166174
wpt.getPageSpeedData('120816_V2_2', {dryRun: true}, function (err, data) {
167175
if (err) return done(err);

test/fixtures/command-line/help-cancel.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
Options:
55

6-
-h, --help output usage information
6+
-h, --help output usage information
7+
-k, --key <api_key> API key (if assigned). Contact the WebPageTest server administrator for a key if required
78

test/fixtures/command-line/help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
locations [options] list locations and the number of pending tests
99
testers [options] list testers status and details
1010
test [options] <url_or_script> run test
11-
cancel <id> cancel running/pending test
11+
cancel [options] <id> cancel running/pending test
1212
har <id> get the HTTPS Archive (HAR) from test
1313
pagespeed [options] <id> get the Google Page Speed results (if available) from test
1414
utilization [options] <id> get the CPU, bandwidth and memory utilization data from test

0 commit comments

Comments
 (0)