@@ -129,10 +129,17 @@ describe('create start instance tests', () => {
129129
130130 it ( 'should create instance from public image' , async ( ) => {
131131 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+ }
136143 assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
137144
138145 execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
@@ -151,11 +158,18 @@ describe('create start instance tests', () => {
151158
152159 const diskSnapshotLink = `projects/${ projectId } /global/snapshots/${ snapshotName } ` ;
153160
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+ }
157172 assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
158-
159173 execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
160174
161175 await deleteDiskSnapshot ( projectId , snapshotName ) ;
@@ -175,11 +189,18 @@ describe('create start instance tests', () => {
175189
176190 const diskSnapshotLink = `projects/${ projectId } /global/snapshots/${ snapshotName } ` ;
177191
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+ }
181203 assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
182-
183204 execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
184205
185206 await deleteDiskSnapshot ( projectId , snapshotName ) ;
@@ -194,9 +215,17 @@ describe('create start instance tests', () => {
194215 family : 'debian-10' ,
195216 } ) ;
196217
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+ }
200229 assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
201230
202231 execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
@@ -205,9 +234,17 @@ describe('create start instance tests', () => {
205234 it ( 'should create instance with additional disk' , async ( ) => {
206235 const projectId = await instancesClient . getProjectId ( ) ;
207236
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+ }
211248 assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
212249
213250 execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
@@ -216,11 +253,18 @@ describe('create start instance tests', () => {
216253 it ( 'should create instance with subnet' , async ( ) => {
217254 const projectId = await instancesClient . getProjectId ( ) ;
218255
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+ }
222267 assert . match ( output , / I n s t a n c e c r e a t e d ./ ) ;
223-
224268 execSync ( `node deleteInstance ${ projectId } ${ zone } ${ instanceName } ` ) ;
225269 } ) ;
226270} ) ;
0 commit comments