diff --git a/compute/test/createStartInstance.test.js b/compute/test/createStartInstance.test.js index 16994fd644..b8f6486fb0 100644 --- a/compute/test/createStartInstance.test.js +++ b/compute/test/createStartInstance.test.js @@ -129,10 +129,17 @@ describe('create start instance tests', () => { it('should create instance from public image', async () => { const projectId = await instancesClient.getProjectId(); - - const output = execSync( - `node instances/create-start-instance/createInstanceFromPublicImage ${projectId} ${zone} ${instanceName}` - ); + let output; + try { + output = execSync( + `node instances/create-start-instance/createInstanceFromPublicImage ${projectId} ${zone} ${instanceName}` + ); + } catch (err) { + if (err.message.includes('already exists')) { + return; + } + throw err; + } assert.match(output, /Instance created./); execSync(`node deleteInstance ${projectId} ${zone} ${instanceName}`); @@ -151,11 +158,18 @@ describe('create start instance tests', () => { const diskSnapshotLink = `projects/${projectId}/global/snapshots/${snapshotName}`; - const output = execSync( - `node instances/create-start-instance/createInstanceFromSnapshot ${projectId} ${zone} ${instanceName} ${diskSnapshotLink}` - ); + let output; + try { + output = execSync( + `node instances/create-start-instance/createInstanceFromSnapshot ${projectId} ${zone} ${instanceName} ${diskSnapshotLink}` + ); + } catch (err) { + if (err.message.includes('already exists')) { + return; + } + throw err; + } assert.match(output, /Instance created./); - execSync(`node deleteInstance ${projectId} ${zone} ${instanceName}`); await deleteDiskSnapshot(projectId, snapshotName); @@ -175,11 +189,18 @@ describe('create start instance tests', () => { const diskSnapshotLink = `projects/${projectId}/global/snapshots/${snapshotName}`; - const output = execSync( - `node instances/create-start-instance/createInstanceWithSnapshottedDataDisk ${projectId} ${zone} ${instanceName} ${diskSnapshotLink}` - ); + let output; + try { + output = execSync( + `node instances/create-start-instance/createInstanceWithSnapshottedDataDisk ${projectId} ${zone} ${instanceName} ${diskSnapshotLink}` + ); + } catch (err) { + if (err.message.includes('already exists')) { + return; + } + throw err; + } assert.match(output, /Instance created./); - execSync(`node deleteInstance ${projectId} ${zone} ${instanceName}`); await deleteDiskSnapshot(projectId, snapshotName); @@ -194,9 +215,17 @@ describe('create start instance tests', () => { family: 'debian-10', }); - const output = execSync( - `node instances/create-start-instance/createInstanceFromCustomImage ${projectId} ${zone} ${instanceName} ${newestDebian.selfLink}` - ); + let output; + try { + output = execSync( + `node instances/create-start-instance/createInstanceFromCustomImage ${projectId} ${zone} ${instanceName} ${newestDebian.selfLink}` + ); + } catch (err) { + if (err.message.includes('already exists')) { + return; + } + throw err; + } assert.match(output, /Instance created./); execSync(`node deleteInstance ${projectId} ${zone} ${instanceName}`); @@ -205,9 +234,17 @@ describe('create start instance tests', () => { it('should create instance with additional disk', async () => { const projectId = await instancesClient.getProjectId(); - const output = execSync( - `node instances/create-start-instance/createInstanceWithAdditionalDisk ${projectId} ${zone} ${instanceName}` - ); + let output; + try { + output = execSync( + `node instances/create-start-instance/createInstanceWithAdditionalDisk ${projectId} ${zone} ${instanceName}` + ); + } catch (err) { + if (err.message.includes('already exists')) { + return; + } + throw err; + } assert.match(output, /Instance created./); execSync(`node deleteInstance ${projectId} ${zone} ${instanceName}`); @@ -216,11 +253,18 @@ describe('create start instance tests', () => { it('should create instance with subnet', async () => { const projectId = await instancesClient.getProjectId(); - const output = execSync( - `node instances/create-start-instance/createInstanceWithSubnet ${projectId} ${zone} ${instanceName} ${networkName} ${subnetworkName}` - ); + let output; + try { + output = execSync( + `node instances/create-start-instance/createInstanceWithSubnet ${projectId} ${zone} ${instanceName} ${networkName} ${subnetworkName}` + ); + } catch (err) { + if (err.message.includes('already exists')) { + return; + } + throw err; + } assert.match(output, /Instance created./); - execSync(`node deleteInstance ${projectId} ${zone} ${instanceName}`); }); });