@@ -129,10 +129,17 @@ describe('create start instance tests', () => {
129
129
130
130
it ( 'should create instance from public image' , async ( ) => {
131
131
const projectId = await instancesClient . getProjectId ( ) ;
132
-
133
- const output = execSync (
134
- `node instances/create-start-instance/createInstanceFromPublicImage ${ projectId } ${ zone } ${ instanceName } `
135
- ) ;
132
+ let output ;
133
+ try {
134
+ output = execSync (
135
+ `node instances/create-start-instance/createInstanceFromPublicImage ${ projectId } ${ zone } ${ instanceName } `
136
+ ) ;
137
+ } catch ( err ) {
138
+ if ( err . message . includes ( 'already exists' ) ) {
139
+ return ;
140
+ }
141
+ throw err ;
142
+ }
136
143
assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
137
144
138
145
execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
@@ -151,11 +158,18 @@ describe('create start instance tests', () => {
151
158
152
159
const diskSnapshotLink = `projects/${ projectId } /global/snapshots/${ snapshotName } ` ;
153
160
154
- const output = execSync (
155
- `node instances/create-start-instance/createInstanceFromSnapshot ${ projectId } ${ zone } ${ instanceName } ${ diskSnapshotLink } `
156
- ) ;
161
+ let output ;
162
+ try {
163
+ output = execSync (
164
+ `node instances/create-start-instance/createInstanceFromSnapshot ${ projectId } ${ zone } ${ instanceName } ${ diskSnapshotLink } `
165
+ ) ;
166
+ } catch ( err ) {
167
+ if ( err . message . includes ( 'already exists' ) ) {
168
+ return ;
169
+ }
170
+ throw err ;
171
+ }
157
172
assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
158
-
159
173
execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
160
174
161
175
await deleteDiskSnapshot ( projectId , snapshotName ) ;
@@ -175,11 +189,18 @@ describe('create start instance tests', () => {
175
189
176
190
const diskSnapshotLink = `projects/${ projectId } /global/snapshots/${ snapshotName } ` ;
177
191
178
- const output = execSync (
179
- `node instances/create-start-instance/createInstanceWithSnapshottedDataDisk ${ projectId } ${ zone } ${ instanceName } ${ diskSnapshotLink } `
180
- ) ;
192
+ let output ;
193
+ try {
194
+ output = execSync (
195
+ `node instances/create-start-instance/createInstanceWithSnapshottedDataDisk ${ projectId } ${ zone } ${ instanceName } ${ diskSnapshotLink } `
196
+ ) ;
197
+ } catch ( err ) {
198
+ if ( err . message . includes ( 'already exists' ) ) {
199
+ return ;
200
+ }
201
+ throw err ;
202
+ }
181
203
assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
182
-
183
204
execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
184
205
185
206
await deleteDiskSnapshot ( projectId , snapshotName ) ;
@@ -194,9 +215,17 @@ describe('create start instance tests', () => {
194
215
family : 'debian-10' ,
195
216
} ) ;
196
217
197
- const output = execSync (
198
- `node instances/create-start-instance/createInstanceFromCustomImage ${ projectId } ${ zone } ${ instanceName } ${ newestDebian . selfLink } `
199
- ) ;
218
+ let output ;
219
+ try {
220
+ output = execSync (
221
+ `node instances/create-start-instance/createInstanceFromCustomImage ${ projectId } ${ zone } ${ instanceName } ${ newestDebian . selfLink } `
222
+ ) ;
223
+ } catch ( err ) {
224
+ if ( err . message . includes ( 'already exists' ) ) {
225
+ return ;
226
+ }
227
+ throw err ;
228
+ }
200
229
assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
201
230
202
231
execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
@@ -205,9 +234,17 @@ describe('create start instance tests', () => {
205
234
it ( 'should create instance with additional disk' , async ( ) => {
206
235
const projectId = await instancesClient . getProjectId ( ) ;
207
236
208
- const output = execSync (
209
- `node instances/create-start-instance/createInstanceWithAdditionalDisk ${ projectId } ${ zone } ${ instanceName } `
210
- ) ;
237
+ let output ;
238
+ try {
239
+ output = execSync (
240
+ `node instances/create-start-instance/createInstanceWithAdditionalDisk ${ projectId } ${ zone } ${ instanceName } `
241
+ ) ;
242
+ } catch ( err ) {
243
+ if ( err . message . includes ( 'already exists' ) ) {
244
+ return ;
245
+ }
246
+ throw err ;
247
+ }
211
248
assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
212
249
213
250
execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
@@ -216,11 +253,18 @@ describe('create start instance tests', () => {
216
253
it ( 'should create instance with subnet' , async ( ) => {
217
254
const projectId = await instancesClient . getProjectId ( ) ;
218
255
219
- const output = execSync (
220
- `node instances/create-start-instance/createInstanceWithSubnet ${ projectId } ${ zone } ${ instanceName } ${ networkName } ${ subnetworkName } `
221
- ) ;
256
+ let output ;
257
+ try {
258
+ output = execSync (
259
+ `node instances/create-start-instance/createInstanceWithSubnet ${ projectId } ${ zone } ${ instanceName } ${ networkName } ${ subnetworkName } `
260
+ ) ;
261
+ } catch ( err ) {
262
+ if ( err . message . includes ( 'already exists' ) ) {
263
+ return ;
264
+ }
265
+ throw err ;
266
+ }
222
267
assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
223
-
224
268
execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
225
269
} ) ;
226
270
} ) ;
0 commit comments