@@ -34,11 +34,8 @@ const options = {
34
34
} ;
35
35
const datasetId = `asset_nodejs_${ uuid . v4 ( ) } ` . replace ( / - / gi, '_' ) ;
36
36
37
- const Compute = require ( '@google-cloud/compute' ) ;
38
- const zone = new Compute ( ) . zone ( 'us-central1-c' ) ;
39
- const vmName = `asset-nodejs-${ uuid . v4 ( ) } ` ;
40
-
41
- let vm ;
37
+ const compute = require ( '@google-cloud/compute' ) ;
38
+ const instancesClient = new compute . InstancesClient ( ) ;
42
39
43
40
// Some of these tests can take an extremely long time, and occasionally
44
41
// timeout, see:
@@ -48,17 +45,68 @@ function sleep(ms) {
48
45
}
49
46
50
47
describe ( 'quickstart sample tests' , ( ) => {
48
+ let projectId ;
49
+ let zone ;
50
+ let instanceName ;
51
+ let machineType ;
52
+ let sourceImage ;
53
+ let networkName ;
51
54
before ( async ( ) => {
55
+ zone = 'us-central1-a' ;
56
+ instanceName = `asset-nodejs-${ uuid . v4 ( ) } ` ;
57
+ machineType = 'n1-standard-1' ;
58
+ sourceImage =
59
+ 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1804-lts' ;
60
+ networkName = 'global/networks/default' ;
61
+ projectId = await instancesClient . getProjectId ( ) ;
62
+
52
63
await bucket . create ( ) ;
53
64
await bigquery . createDataset ( datasetId , options ) ;
54
65
await bigquery . dataset ( datasetId ) . exists ( ) ;
55
- [ vm ] = await zone . createVM ( vmName , { os : 'ubuntu' } ) ;
66
+ // [vm] = await zone.vm(vmName, {os: 'ubuntu'});
67
+
68
+ const [ response ] = await instancesClient . insert ( {
69
+ instanceResource : {
70
+ name : instanceName ,
71
+ disks : [
72
+ {
73
+ // Describe the size and source image of the boot disk to attach to the instance.
74
+ initializeParams : {
75
+ diskSizeGb : '10' ,
76
+ sourceImage,
77
+ } ,
78
+ autoDelete : true ,
79
+ boot : true ,
80
+ type : 'PERSISTENT' ,
81
+ } ,
82
+ ] ,
83
+ machineType : `zones/${ zone } /machineTypes/${ machineType } ` ,
84
+ networkInterfaces : [
85
+ {
86
+ // Use the network interface provided in the networkName argument.
87
+ name : networkName ,
88
+ } ,
89
+ ] ,
90
+ } ,
91
+ project : projectId ,
92
+ zone,
93
+ } ) ;
94
+ let operation = response . latestResponse ;
95
+ const operationsClient = new compute . ZoneOperationsClient ( ) ;
96
+
97
+ // Wait for the create operation to complete.
98
+ while ( operation . status !== 'DONE' ) {
99
+ [ operation ] = await operationsClient . wait ( {
100
+ operation : operation . name ,
101
+ project : projectId ,
102
+ zone : operation . zone . split ( '/' ) . pop ( ) ,
103
+ } ) ;
104
+ }
56
105
} ) ;
57
106
58
107
after ( async ( ) => {
59
108
await bucket . delete ( ) ;
60
109
await bigquery . dataset ( datasetId ) . delete ( { force : true } ) . catch ( console . warn ) ;
61
- await vm . delete ( ) ;
62
110
} ) ;
63
111
64
112
it ( 'should export assets to specified path' , async ( ) => {
@@ -114,10 +162,10 @@ describe('quickstart sample tests', () => {
114
162
assert . include ( stdout , assetName ) ;
115
163
} ) ;
116
164
117
- it . skip ( 'should search all resources successfully' , async ( ) => {
118
- const query = `name:${ vmName } ` ;
165
+ it ( 'should search all resources successfully' , async ( ) => {
166
+ const query = `name:${ instanceName } ` ;
119
167
const stdout = execSync ( `node searchAllResources '' ${ query } ` ) ;
120
- assert . include ( stdout , vmName ) ;
168
+ assert . include ( stdout , instanceName ) ;
121
169
} ) ;
122
170
123
171
it ( 'should search all iam policies successfully' , async ( ) => {
0 commit comments