Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
test(samples): do not try creating an instance if it already exists (#…
Browse files Browse the repository at this point in the history
…756)

* test(samples): do not try creating an instance if it already exists
  • Loading branch information
sofisl authored Jul 13, 2022
1 parent 8ff77f6 commit ec6cbed
Showing 1 changed file with 66 additions and 22 deletions.
88 changes: 66 additions & 22 deletions samples/test/createStartInstance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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}`);
Expand All @@ -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}`);
Expand All @@ -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}`);
});
});

0 comments on commit ec6cbed

Please sign in to comment.