Skip to content

Commit

Permalink
Refactor for compute samples
Browse files Browse the repository at this point in the history
  • Loading branch information
gryczj committed Sep 16, 2024
1 parent 7bc56c9 commit bce6e24
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 129 deletions.
10 changes: 1 addition & 9 deletions compute/disks/createComputeHyperdisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,7 @@ async function main(diskName) {
});
}

const hyperdisk = (
await disksClient.get({
project: projectId,
zone,
disk: diskName,
})
)[0];

console.log(JSON.stringify(hyperdisk));
console.log(`Disk: ${diskName} created.`);
}

await callCreateComputeHyperdisk();
Expand Down
10 changes: 1 addition & 9 deletions compute/disks/createComputeHyperdiskFromPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,7 @@ async function main(diskName, storagePoolName) {
});
}

const hyperdisk = (
await disksClient.get({
project: projectId,
zone,
disk: diskName,
})
)[0];

console.log(JSON.stringify(hyperdisk));
console.log(`Disk: ${diskName} created.`);
}

await callCreateComputeHyperdiskFromPool();
Expand Down
10 changes: 1 addition & 9 deletions compute/disks/createComputeHyperdiskPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,7 @@ async function main(storagePoolName) {
});
}

const createdStoragePool = (
await storagePoolClient.get({
project: projectId,
zone,
storagePool: storagePoolName,
})
)[0];

console.log(JSON.stringify(createdStoragePool));
console.log(`Storage pool: ${storagePoolName} created.`);
}

await callCreateComputeHyperdiskPool();
Expand Down
10 changes: 1 addition & 9 deletions compute/reservations/createReservationFromProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,7 @@ async function main(reservationName) {
});
}

const createdReservation = (
await reservationsClient.get({
project: projectId,
zone,
reservation: reservationName,
})
)[0];

console.log(JSON.stringify(createdReservation));
console.log(`Reservation: ${reservationName} created.`);
}

await callCreateComputeReservationFromProperties();
Expand Down
10 changes: 1 addition & 9 deletions compute/reservations/createReservationInstanceTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,7 @@ async function main(reservationName, location, instanceTemplateName) {
});
}

const createdReservation = (
await reservationsClient.get({
project: projectId,
zone,
reservation: reservationName,
})
)[0];

console.log(JSON.stringify(createdReservation));
console.log(`Reservation: ${reservationName} created.`);
}

await callCreateComputeReservationInstanceTemplate();
Expand Down
10 changes: 1 addition & 9 deletions compute/reservations/createSharedReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,7 @@ async function main(reservationName, instanceTemplateName) {
});
}

const createdReservation = (
await reservationsClient.get({
project: projectId,
zone,
reservation: reservationName,
})
)[0];

console.log(createdReservation);
console.log(`Reservation: ${reservationName} created.`);
}

await callCreateComputeSharedReservation();
Expand Down
2 changes: 2 additions & 0 deletions compute/reservations/deleteReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ async function main(reservationName) {
zone: operation.zone.split('/').pop(),
});
}

console.log(`Reservation: ${reservationName} deleted.`);
}
await callDeleteReservation();
// [END compute_reservation_delete]
Expand Down
10 changes: 1 addition & 9 deletions compute/reservations/reservationVmsUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,7 @@ async function main(reservationName) {
});
}

const updatedReservation = (
await reservationsClient.get({
project: projectId,
zone,
reservation: reservationName,
})
)[0];

console.log(JSON.stringify(updatedReservation));
console.log(`Reservation: ${reservationName} updated.`);
}

await callComputeReservationVmsUpdate();
Expand Down
10 changes: 1 addition & 9 deletions compute/reservations/sharedReservationConsumerProjectsUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,7 @@ async function main(reservationName) {
});
}

const updatedReservation = (
await reservationsClient.get({
project: projectId,
zone,
reservation: reservationName,
})
)[0];

console.log(updatedReservation);
console.log(`Reservation: ${reservationName} updated.`);
}

await callComputeSharedReservationConsumerProjectsUpdate();
Expand Down
9 changes: 5 additions & 4 deletions compute/test/createComputeHyperdisk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ describe('Create compute hyperdisk', async () => {
});

it('should create a new hyperdisk', () => {
const response = JSON.parse(
execSync(`node ./disks/createComputeHyperdisk.js ${diskName}`, {
const response = execSync(
`node ./disks/createComputeHyperdisk.js ${diskName}`,
{
cwd,
})
}
);

assert.equal(response.name, diskName);
assert.equal(response, `Disk: ${diskName} created.`);
});
});
28 changes: 12 additions & 16 deletions compute/test/createComputeHyperdiskFromPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,24 @@ describe('Create compute hyperdisk from pool', async () => {
});

it('should create a new storage pool', () => {
const response = JSON.parse(
execSync(
`node ./disks/createComputeHyperdiskPool.js ${storagePoolName}`,
{
cwd,
}
)
const response = execSync(
`node ./disks/createComputeHyperdiskPool.js ${storagePoolName}`,
{
cwd,
}
);

assert.equal(response.name, storagePoolName);
assert.equal(response, `Storage pool: ${storagePoolName} created.`);
});

it('should create a new hyperdisk from pool', () => {
const response = JSON.parse(
execSync(
`node ./disks/createComputeHyperdiskFromPool.js ${diskName} ${storagePoolName}`,
{
cwd,
}
)
const response = execSync(
`node ./disks/createComputeHyperdiskFromPool.js ${diskName} ${storagePoolName}`,
{
cwd,
}
);

assert.equal(response.name, diskName);
assert.equal(response, `Disk: ${diskName} created.`);
});
});
14 changes: 6 additions & 8 deletions compute/test/createReservationGlobalInstanceTemplate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ describe('Create compute reservation using global instance template', async () =
});

it('should create a new reservation', () => {
const response = JSON.parse(
execSync(
`node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`,
{
cwd,
}
)
const response = execSync(
`node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`,
{
cwd,
}
);

assert.equal(response.name, reservationName);
assert.equal(response, `Reservation: ${reservationName} created.`);
});
});
15 changes: 6 additions & 9 deletions compute/test/createReservationRegionalInstanceTemplate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ describe('Create compute reservation using regional instance template', async ()
});

it('should create a new reservation', () => {
const response = JSON.parse(
execSync(
`node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`,
{
cwd,
}
)
const response = execSync(
`node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`,
{
cwd,
}
);

assert.equal(response.name, reservationName);
assert.equal(response, `Reservation: ${reservationName} created.`);
});
});
16 changes: 6 additions & 10 deletions compute/test/reservations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,19 @@ describe('Compute reservation', async () => {
const zone = 'us-central1-a';
const reservationsClient = new ReservationsClient();
let projectId;
let reservation;

before(async () => {
projectId = await reservationsClient.getProjectId();
});

it('should create a new reservation', () => {
reservation = JSON.parse(
execSync(
`node ./reservations/createReservationFromProperties.js ${reservationName}`,
{
cwd,
}
)
const response = execSync(
`node ./reservations/createReservationFromProperties.js ${reservationName}`,
{
cwd,
}
);

assert.equal(reservation.name, reservationName);
assert.equal(response, `Reservation: ${reservationName} created.`);
});

it('should return reservation', () => {
Expand Down
17 changes: 7 additions & 10 deletions compute/test/sharedReservation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ describe('Compute shared reservation', async () => {
});

it('should create new shared reservation', async () => {
const response = JSON.parse(
execSync(
`node ./reservations/createSharedReservation.js ${reservationName}`,
{
cwd,
}
)
const response = execSync(
`node ./reservations/createSharedReservation.js ${reservationName}`,
{
cwd,
}
);

assert.equal(response.name, reservationName);
assert.equal(response, `Reservation: ${reservationName} created.`);
});

it('should update consumer projects in shared reservation', async () => {
Expand All @@ -57,6 +54,6 @@ describe('Compute shared reservation', async () => {
)
);

assert.not.equal(response, null);
assert.equal(response, `Reservation: ${reservationName} updated.`);
});
});

0 comments on commit bce6e24

Please sign in to comment.