Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource: use default method options & run system tests conditionally #960

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/resource/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ function Project(resource, id) {
* }
* });
*/
setMetadata: true
setMetadata: {
reqOpts: {
method: 'PUT'
}
}
};

ServiceObject.call(this, {
Expand Down
110 changes: 63 additions & 47 deletions system-test/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,14 @@
'use strict';

var assert = require('assert');
var googleAuth = require('google-auto-auth');

var env = require('./env.js');
var Resource = require('../lib/resource/index.js');

describe('Resource', function() {
// -------------
// >> Attention!
// -------------
// As of 9/14/15, creating projects is not supported. Once we have support,
// the following description outlines how we should run our tests.
// -------------
//
// Before the tests run, we create a project. That acts as the test for being
// able to create a project. Similarly, the after hook deletes it, testing if
// a project can be deleted.
//
// ----------
// >> Notice!
// ----------
// All tests should only manipulate a short-lived project. NOT the project the
// user has been running our test suite with. That would just be rude.
// ----------

// var PROJECT_ID = 'gcloud-tests-' + Date.now();
var PROJECT_NAME = 'gcloud-tests-project-name';

var resource = new Resource(env);
var project;

before(function(done) {
// Uncomment after we support creating a project.
// resource.createProject(PROJECT_ID, function(err, project_) {
// if (err) {
// done(err);
// return;
// }
//
// project = project_;
// });

// ** SEE "Notice!" SECTION ABOVE **
// Remove once we support creating a project.
project = resource.project();
done();
});

// Uncomment after we support creating a project.
// after(function(done) {
// project.delete(done);
// });
var project = resource.project();

describe('resource', function() {
it('should get a list of projects', function(done) {
Expand Down Expand Up @@ -100,15 +58,73 @@ describe('Resource', function() {
done();
});
});
});

// Auth through the gcloud SDK is required to:
//
// - Create a project
// - Set metadata
// - Restore a project
// - Delete a project
describe('lifecycle', function() {
var CAN_RUN_TESTS = true;

var resource = new Resource({
projectId: env.projectId
});

var PROJECT_ID = 'gcloud-tests-' + Date.now();
var project = resource.project(PROJECT_ID);

before(function(done) {
var authClient = googleAuth();

// See if an auth token exists.
authClient.getToken(function(err) {
if (err) {
if (err.code === 400) {
CAN_RUN_TESTS = false;
done();
} else {
done(err);
}
return;
}

project.create(done);
});
});

beforeEach(function() {
if (!CAN_RUN_TESTS) {
this.skip();
}
});

after(function(done) {
if (!CAN_RUN_TESTS) {
this.skip();
return;
}

project.delete(done);
});

it('should have created the project', function() {
assert.strictEqual(project.metadata.projectId, PROJECT_ID);
});

it('should set metadata', function(done) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

var newProjectName = 'gcloud-tests-project-name';

it.skip('should set metadata', function(done) {
project.getMetadata(function(err, metadata) {
assert.ifError(err);

var originalProjectName = metadata.name;
assert.notStrictEqual(originalProjectName, newProjectName);

project.setMetadata({
name: PROJECT_NAME
name: newProjectName
}, function(err) {
assert.ifError(err);

Expand All @@ -119,7 +135,7 @@ describe('Resource', function() {
});
});

it.skip('should delete and restore a project', function(done) {
it('should restore the project', function(done) {
project.delete(function(err) {
assert.ifError(err);
project.restore(done);
Expand Down
6 changes: 5 additions & 1 deletion test/resource/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ describe('Project', function() {
exists: true,
get: true,
getMetadata: true,
setMetadata: true
setMetadata: {
reqOpts: {
method: 'PUT'
}
}
});
});
});
Expand Down