17
17
'use strict' ;
18
18
19
19
var assert = require ( 'assert' ) ;
20
+ var googleAuth = require ( 'google-auto-auth' ) ;
20
21
21
22
var env = require ( './env.js' ) ;
22
23
var Resource = require ( '../lib/resource/index.js' ) ;
23
24
24
25
describe ( 'Resource' , function ( ) {
25
- // -------------
26
- // >> Attention!
27
- // -------------
28
- // As of 9/14/15, creating projects is not supported. Once we have support,
29
- // the following description outlines how we should run our tests.
30
- // -------------
31
- //
32
- // Before the tests run, we create a project. That acts as the test for being
33
- // able to create a project. Similarly, the after hook deletes it, testing if
34
- // a project can be deleted.
35
- //
36
- // ----------
37
- // >> Notice!
38
- // ----------
39
- // All tests should only manipulate a short-lived project. NOT the project the
40
- // user has been running our test suite with. That would just be rude.
41
- // ----------
42
-
43
- // var PROJECT_ID = 'gcloud-tests-' + Date.now();
44
- var PROJECT_NAME = 'gcloud-tests-project-name' ;
45
-
46
26
var resource = new Resource ( env ) ;
47
- var project ;
48
-
49
- before ( function ( done ) {
50
- // Uncomment after we support creating a project.
51
- // resource.createProject(PROJECT_ID, function(err, project_) {
52
- // if (err) {
53
- // done(err);
54
- // return;
55
- // }
56
- //
57
- // project = project_;
58
- // });
59
-
60
- // ** SEE "Notice!" SECTION ABOVE **
61
- // Remove once we support creating a project.
62
- project = resource . project ( ) ;
63
- done ( ) ;
64
- } ) ;
65
-
66
- // Uncomment after we support creating a project.
67
- // after(function(done) {
68
- // project.delete(done);
69
- // });
27
+ var project = resource . project ( ) ;
70
28
71
29
describe ( 'resource' , function ( ) {
72
30
it ( 'should get a list of projects' , function ( done ) {
@@ -100,15 +58,73 @@ describe('Resource', function() {
100
58
done ( ) ;
101
59
} ) ;
102
60
} ) ;
61
+ } ) ;
62
+
63
+ // Auth through the gcloud SDK is required to:
64
+ //
65
+ // - Create a project
66
+ // - Set metadata
67
+ // - Restore a project
68
+ // - Delete a project
69
+ describe ( 'lifecycle' , function ( ) {
70
+ var CAN_RUN_TESTS = true ;
71
+
72
+ var resource = new Resource ( {
73
+ projectId : env . projectId
74
+ } ) ;
75
+
76
+ var PROJECT_ID = 'gcloud-tests-' + Date . now ( ) ;
77
+ var project = resource . project ( PROJECT_ID ) ;
78
+
79
+ before ( function ( done ) {
80
+ var authClient = googleAuth ( ) ;
81
+
82
+ // See if an auth token exists.
83
+ authClient . getToken ( function ( err ) {
84
+ if ( err ) {
85
+ if ( err . code === 400 ) {
86
+ CAN_RUN_TESTS = false ;
87
+ done ( ) ;
88
+ } else {
89
+ done ( err ) ;
90
+ }
91
+ return ;
92
+ }
93
+
94
+ project . create ( done ) ;
95
+ } ) ;
96
+ } ) ;
97
+
98
+ beforeEach ( function ( ) {
99
+ if ( ! CAN_RUN_TESTS ) {
100
+ this . skip ( ) ;
101
+ }
102
+ } ) ;
103
+
104
+ after ( function ( done ) {
105
+ if ( ! CAN_RUN_TESTS ) {
106
+ this . skip ( ) ;
107
+ return ;
108
+ }
109
+
110
+ project . delete ( done ) ;
111
+ } ) ;
112
+
113
+ it ( 'should have created the project' , function ( ) {
114
+ assert . strictEqual ( project . metadata . projectId , PROJECT_ID ) ;
115
+ } ) ;
116
+
117
+ it ( 'should set metadata' , function ( done ) {
118
+ var newProjectName = 'gcloud-tests-project-name' ;
103
119
104
- it . skip ( 'should set metadata' , function ( done ) {
105
120
project . getMetadata ( function ( err , metadata ) {
106
121
assert . ifError ( err ) ;
107
122
108
123
var originalProjectName = metadata . name ;
124
+ assert . notStrictEqual ( originalProjectName , newProjectName ) ;
109
125
110
126
project . setMetadata ( {
111
- name : PROJECT_NAME
127
+ name : newProjectName
112
128
} , function ( err ) {
113
129
assert . ifError ( err ) ;
114
130
@@ -119,7 +135,7 @@ describe('Resource', function() {
119
135
} ) ;
120
136
} ) ;
121
137
122
- it . skip ( 'should delete and restore a project' , function ( done ) {
138
+ it ( 'should restore the project' , function ( done ) {
123
139
project . delete ( function ( err ) {
124
140
assert . ifError ( err ) ;
125
141
project . restore ( done ) ;
0 commit comments