Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
controller API requires Debuggee.description (#205)
Browse files Browse the repository at this point in the history
Make this a mandatory property for Debuggee
  • Loading branch information
ofrobots committed Dec 22, 2016
1 parent 03f4b97 commit b19b32d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/debuggee.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var _ = require('lodash');
* project. Any string that identifies the application within the project
* can be used. Including environment and version or build IDs is
* recommended.
* @param {?string} properties.description - A user specified string identifyin
* this debuggable instance (default: none)
* @param {string} properties.description - A user specified string identifying
* this debuggable instance.
* @param {?string} properties.agentVersion - version ID of the agent. (default:
* the version of this module)
* @param {?object} labels - a set of custom properties about the debuggee that
Expand All @@ -55,14 +55,15 @@ function Debuggee(properties) {
if (!_.isString(properties.uniquifier)) {
throw new Error('properties.uniquifier must be a string');
}
if (!_.isString(properties.description)) {
throw new Error('properties.description must be a string');
}

this.project = properties.project;
this.uniquifier = properties.uniquifier;
this.description = properties.description;
this.agentVersion =
properties.agentVersion || (pjson.name + '/default/v' + pjson.version);
if (properties.description) {
this.description = properties.description;
}
properties.agentVersion || (pjson.name + '/client/v' + pjson.version);
if (properties.labels) {
this.labels = properties.labels;
}
Expand Down
6 changes: 4 additions & 2 deletions system-test/test-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ describe('Controller', function() {
var debuggee =
new Debuggee({
project: process.env.GCLOUD_PROJECT,
uniquifier: 'test-uid-' + Date.now()
uniquifier: 'test-uid-' + Date.now(),
description: 'this is a system test'
});

controller.register(debuggee, function(err, body) {
Expand All @@ -55,7 +56,8 @@ describe('Controller', function() {
var debuggee =
new Debuggee({
project: process.env.GCLOUD_PROJECT,
uniquifier: 'test-uid-' + Date.now()
uniquifier: 'test-uid-' + Date.now(),
description: 'this is a system test'
});
controller.register(debuggee, function(err, body) {
assert.ifError(err, 'should be able to register successfully');
Expand Down
28 changes: 20 additions & 8 deletions test/test-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ describe('Controller API', function() {
.post(api + '/debuggees/register')
.reply(200,
{debuggee: {id: 'fake-debuggee'}, activePeriodSec: 600});
var debuggee =
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
var debuggee = new Debuggee({
project: 'fake-project',
uniquifier: 'fake-id',
description: 'unit test'
});
var controller = new Controller(fakeDebug);
controller.register(debuggee, function(err, result) {
assert(!err, 'not expecting an error');
Expand All @@ -77,8 +80,11 @@ describe('Controller API', function() {
.post(api + '/debuggees/register')
.reply(200,
{debuggee: {id: 'fake-debuggee'}, activePeriodSec: 600});
var debuggee =
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
var debuggee = new Debuggee({
project: 'fake-project',
uniquifier: 'fake-id',
description: 'unit test'
});
controller.register(debuggee, function(err, result) {
assert(!err, 'not expecting an error');
assert.equal(result.debuggee.id, 'fake-debuggee');
Expand All @@ -99,8 +105,11 @@ describe('Controller API', function() {
},
activePeriodSec: 600,
});
var debuggee =
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
var debuggee = new Debuggee({
project: 'fake-project',
uniquifier: 'fake-id',
description: 'unit test'
});
var controller = new Controller(fakeDebug);
controller.register(debuggee, function(err/*, result*/) {
assert(err, 'expected an error');
Expand All @@ -121,8 +130,11 @@ describe('Controller API', function() {
debuggee: { id: 'fake-debuggee' },
activePeriodSec: 600
});
var debuggee =
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
var debuggee = new Debuggee({
project: 'fake-project',
uniquifier: 'fake-id',
description: 'unit test'
});
var controller = new Controller(fakeDebug);
controller.register(debuggee, function(err/*, result*/) {
assert.ifError(err);
Expand Down
9 changes: 7 additions & 2 deletions test/test-debuggee.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ var Debuggee = require('../src/debuggee.js');
describe('Debuggee', function() {

it('should create a Debuggee instance on valid input', function() {
var debuggee = new Debuggee({project:'project', uniquifier: 'uid'});
var debuggee = new Debuggee(
{project: 'project', uniquifier: 'uid', description: 'unit test'});
assert.ok(debuggee instanceof Debuggee);
});

it('should create a Debuggee on a call without new', function() {
var debuggee = new Debuggee({project:'project', uniquifier: 'uid'});
var debuggee = new Debuggee(
{project: 'project', uniquifier: 'uid', description: 'unit test'});
assert.ok(debuggee instanceof Debuggee);
});

Expand All @@ -37,6 +39,9 @@ describe('Debuggee', function() {
assert.throws(function() { new Debuggee({project: 'test'}); });
assert.throws(function() {
new Debuggee({project: 'test', uniquifier: null});
assert.throws(function() {
new Debuggee({project: 'test', uniquifier: 'uid'});
});
});
});

Expand Down

0 comments on commit b19b32d

Please sign in to comment.