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

Commit b19b32d

Browse files
authored
controller API requires Debuggee.description (#205)
Make this a mandatory property for Debuggee
1 parent 03f4b97 commit b19b32d

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

src/debuggee.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ var _ = require('lodash');
2929
* project. Any string that identifies the application within the project
3030
* can be used. Including environment and version or build IDs is
3131
* recommended.
32-
* @param {?string} properties.description - A user specified string identifyin
33-
* this debuggable instance (default: none)
32+
* @param {string} properties.description - A user specified string identifying
33+
* this debuggable instance.
3434
* @param {?string} properties.agentVersion - version ID of the agent. (default:
3535
* the version of this module)
3636
* @param {?object} labels - a set of custom properties about the debuggee that
@@ -55,14 +55,15 @@ function Debuggee(properties) {
5555
if (!_.isString(properties.uniquifier)) {
5656
throw new Error('properties.uniquifier must be a string');
5757
}
58+
if (!_.isString(properties.description)) {
59+
throw new Error('properties.description must be a string');
60+
}
5861

5962
this.project = properties.project;
6063
this.uniquifier = properties.uniquifier;
64+
this.description = properties.description;
6165
this.agentVersion =
62-
properties.agentVersion || (pjson.name + '/default/v' + pjson.version);
63-
if (properties.description) {
64-
this.description = properties.description;
65-
}
66+
properties.agentVersion || (pjson.name + '/client/v' + pjson.version);
6667
if (properties.labels) {
6768
this.labels = properties.labels;
6869
}

system-test/test-controller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ describe('Controller', function() {
3838
var debuggee =
3939
new Debuggee({
4040
project: process.env.GCLOUD_PROJECT,
41-
uniquifier: 'test-uid-' + Date.now()
41+
uniquifier: 'test-uid-' + Date.now(),
42+
description: 'this is a system test'
4243
});
4344

4445
controller.register(debuggee, function(err, body) {
@@ -55,7 +56,8 @@ describe('Controller', function() {
5556
var debuggee =
5657
new Debuggee({
5758
project: process.env.GCLOUD_PROJECT,
58-
uniquifier: 'test-uid-' + Date.now()
59+
uniquifier: 'test-uid-' + Date.now(),
60+
description: 'this is a system test'
5961
});
6062
controller.register(debuggee, function(err, body) {
6163
assert.ifError(err, 'should be able to register successfully');

test/test-controller.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ describe('Controller API', function() {
5454
.post(api + '/debuggees/register')
5555
.reply(200,
5656
{debuggee: {id: 'fake-debuggee'}, activePeriodSec: 600});
57-
var debuggee =
58-
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
57+
var debuggee = new Debuggee({
58+
project: 'fake-project',
59+
uniquifier: 'fake-id',
60+
description: 'unit test'
61+
});
5962
var controller = new Controller(fakeDebug);
6063
controller.register(debuggee, function(err, result) {
6164
assert(!err, 'not expecting an error');
@@ -77,8 +80,11 @@ describe('Controller API', function() {
7780
.post(api + '/debuggees/register')
7881
.reply(200,
7982
{debuggee: {id: 'fake-debuggee'}, activePeriodSec: 600});
80-
var debuggee =
81-
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
83+
var debuggee = new Debuggee({
84+
project: 'fake-project',
85+
uniquifier: 'fake-id',
86+
description: 'unit test'
87+
});
8288
controller.register(debuggee, function(err, result) {
8389
assert(!err, 'not expecting an error');
8490
assert.equal(result.debuggee.id, 'fake-debuggee');
@@ -99,8 +105,11 @@ describe('Controller API', function() {
99105
},
100106
activePeriodSec: 600,
101107
});
102-
var debuggee =
103-
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
108+
var debuggee = new Debuggee({
109+
project: 'fake-project',
110+
uniquifier: 'fake-id',
111+
description: 'unit test'
112+
});
104113
var controller = new Controller(fakeDebug);
105114
controller.register(debuggee, function(err/*, result*/) {
106115
assert(err, 'expected an error');
@@ -121,8 +130,11 @@ describe('Controller API', function() {
121130
debuggee: { id: 'fake-debuggee' },
122131
activePeriodSec: 600
123132
});
124-
var debuggee =
125-
new Debuggee({project: 'fake-project', uniquifier: 'fake-id'});
133+
var debuggee = new Debuggee({
134+
project: 'fake-project',
135+
uniquifier: 'fake-id',
136+
description: 'unit test'
137+
});
126138
var controller = new Controller(fakeDebug);
127139
controller.register(debuggee, function(err/*, result*/) {
128140
assert.ifError(err);

test/test-debuggee.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ var Debuggee = require('../src/debuggee.js');
2121
describe('Debuggee', function() {
2222

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

2829
it('should create a Debuggee on a call without new', function() {
29-
var debuggee = new Debuggee({project:'project', uniquifier: 'uid'});
30+
var debuggee = new Debuggee(
31+
{project: 'project', uniquifier: 'uid', description: 'unit test'});
3032
assert.ok(debuggee instanceof Debuggee);
3133
});
3234

@@ -37,6 +39,9 @@ describe('Debuggee', function() {
3739
assert.throws(function() { new Debuggee({project: 'test'}); });
3840
assert.throws(function() {
3941
new Debuggee({project: 'test', uniquifier: null});
42+
assert.throws(function() {
43+
new Debuggee({project: 'test', uniquifier: 'uid'});
44+
});
4045
});
4146
});
4247

0 commit comments

Comments
 (0)