Skip to content

Commit 2f4b2fb

Browse files
more system tests
1 parent e0a7e63 commit 2f4b2fb

2 files changed

Lines changed: 70 additions & 5 deletions

File tree

lib/compute/vm.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,30 @@ VM.prototype.delete = function(callback) {
156156
*
157157
* @resource [Instance: detachDisk API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/instances/detachDisk}
158158
*
159-
* @param {string} deviceName - The name of the device to detach.
159+
* @throws {Error} if a {module:compute/disk} is not provided.
160+
*
161+
* @param {module:compute/disk} disk - The disk to detach.
160162
* @param {function} callback - The callback function.
161163
* @param {?error} callback.err - An error returned while making this request.
162164
* @param {module:compute/operation} callback.operation - An operation object
163165
* that can be used to check the status of the request.
164166
* @param {object} callback.apiResponse - The full API response.
165167
*
166168
* @example
167-
* vm.detachDisk('my-device', function(err, operation, apiResponse) {
169+
* var disk = zone.disk('my-disk');
170+
*
171+
* vm.detachDisk(disk, function(err, operation, apiResponse) {
168172
* // `operation` is an Operation object that can be used to check the status
169173
* // of the request.
170174
* });
171175
*/
172-
VM.prototype.detachDisk = function(deviceName, callback) {
176+
VM.prototype.detachDisk = function(disk, callback) {
177+
if (!(disk instanceof Disk)) {
178+
throw new Error('A Disk object must be provided.');
179+
}
180+
173181
var query = {
174-
deviceName: deviceName
182+
deviceName: disk.name
175183
};
176184

177185
this.makeReq_('POST', '/detachDisk', query, null, callback);
@@ -239,7 +247,7 @@ VM.prototype.getSerialPortOutput = function(port, callback) {
239247
return;
240248
}
241249

242-
callback(null, resp.content, resp);
250+
callback(null, resp.contents, resp);
243251
});
244252
};
245253

system-test/compute.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,63 @@ describe('Compute', function() {
454454
it('should access a VM through a Zone', function(done) {
455455
zone.vm(VM_NAME).getMetadata(done);
456456
});
457+
458+
it('should attach and detach a disk', function(done) {
459+
compute.getDisks()
460+
.on('error', done)
461+
.once('data', function(disk) {
462+
this.end();
463+
464+
vm.attachDisk(disk, function(err) {
465+
assert.ifError(err);
466+
467+
vm.detachDisk(disk, function(err, operation) {
468+
assert.ifError(err);
469+
operation.onComplete(done);
470+
});
471+
});
472+
});
473+
});
474+
475+
it('should get serial port output', function(done) {
476+
vm.getSerialPortOutput(done);
477+
});
478+
479+
it('should set tags', function(done) {
480+
var newTagName = 'new-tag';
481+
482+
vm.getTags(function(err, tags, fingerprint) {
483+
assert.ifError(err);
484+
485+
tags.push(newTagName);
486+
487+
vm.setTags(tags, fingerprint, function(err, operation) {
488+
assert.ifError(err);
489+
490+
operation.onComplete(function(err) {
491+
assert.ifError(err);
492+
493+
vm.getTags(function(err, tags) {
494+
assert.ifError(err);
495+
assert(tags.indexOf(newTagName) > -1);
496+
done();
497+
});
498+
});
499+
});
500+
});
501+
});
502+
503+
it('should reset', function(done) {
504+
vm.reset(done);
505+
});
506+
507+
it('should start', function(done) {
508+
vm.start(done);
509+
});
510+
511+
it('should stop', function(done) {
512+
vm.stop(done);
513+
});
457514
});
458515

459516
describe('zones', function() {

0 commit comments

Comments
 (0)