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

Commit

Permalink
test: additional tests for group manager (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiyekkert authored Jul 23, 2021
1 parent df53b41 commit 84ba87f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"@types/node": "^14.14.13",
"@types/sinon": "^9.0.9",
"c8": "^7.3.5",
"chai": "^4.3.4",
"gts": "^3.0.3",
"jsdoc": "^3.6.6",
"jsdoc-fresh": "^1.0.2",
Expand Down
87 changes: 78 additions & 9 deletions system-test/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
'use strict';

const assert = require('assert');
const expect = require('chai').expect;
const uuid = require('uuid');
const compute = require('../');

const Status = compute.protos.google.cloud.compute.v1.Operation.Status;
const DiskType = compute.protos.google.cloud.compute.v1.AttachedDisk.Type;

describe('Compute', () => {
Expand Down Expand Up @@ -142,6 +142,7 @@ describe('Compute', () => {
this.timeout(10 * 60 * 1000);
const instanceResource = {
name: INSTANCE_NAME,
description: 'test',
machineType: `zones/${zone}/machineTypes/n1-standard-1`,
disks: [
{
Expand All @@ -160,7 +161,6 @@ describe('Compute', () => {
},
],
};

const [insertResponse] = await client.insert({
project,
zone,
Expand Down Expand Up @@ -211,6 +211,46 @@ describe('Compute', () => {
});
assert.strictEqual(fetched.shieldedInstanceConfig.enableSecureBoot, true);
});

it('API errors propagated', async () => {
let error = null;
try {
await client.get({
project,
zone,
instance: 'notexist555',
});
} catch (err) {
error = err;
}
expect(error).to.be.an('Error');
expect(error.message).to.contain('was not found');
expect(error.code).to.equal(404);
});

it('instances update desc to an empty string', async function () {
this.timeout(10 * 60 * 1000);
const [instance] = await client.get({
project,
zone,
instance: INSTANCE_NAME,
});
assert.strictEqual(instance.description, 'test');
instance.description = '';
const [updateOp] = await client.update({
project: project,
zone: zone,
instance: INSTANCE_NAME,
instanceResource: instance,
});
await waitZonalOperation(updateOp);
const [fetched] = await client.get({
project,
zone,
instance: INSTANCE_NAME,
});
assert.strictEqual(fetched.description, '');
});
});

describe('InstancesGroup Manager', () => {
Expand Down Expand Up @@ -243,7 +283,8 @@ describe('Compute', () => {
});
});

it('test instance group manager resize to 0', async function () {
it('create instance group manager with size 0', async function () {
// we want to test that body field can be set to 0
this.timeout(10 * 60 * 1000);
const instanceTemplate = {
name: instanceTemplateName,
Expand Down Expand Up @@ -276,7 +317,7 @@ describe('Compute', () => {
baseInstanceName: 'tsgapic',
instanceTemplate: insertOp.targetLink,
name: instanceGroupName,
targetSize: 1,
targetSize: 0,
};
const [insertGroup] = await clientInstanceGroups.insert({
project,
Expand All @@ -285,11 +326,22 @@ describe('Compute', () => {
});
await waitZonalOperation(insertGroup);

const [fetch] = await clientInstanceGroups.get({
project,
zone,
instanceGroupManager: instanceGroupName,
});
assert.strictEqual(fetch.targetSize, 0);
});

it('Resize group to 1 and then back to 0.', async function () {
// we want to test that query param field can be set to 0
this.timeout(10 * 60 * 1000);
const [resize] = await clientInstanceGroups.resize({
project,
zone,
instanceGroupManager: instanceGroupName,
size: 0,
size: 1,
});
await waitZonalOperation(resize);

Expand All @@ -298,18 +350,34 @@ describe('Compute', () => {
zone,
instanceGroupManager: instanceGroupName,
});
assert.strictEqual(fetch.targetSize, 0);
assert.strictEqual(fetch.targetSize, 1);

const [resizeBack] = await clientInstanceGroups.resize({
project,
zone,
instanceGroupManager: instanceGroupName,
size: 0,
});
await waitZonalOperation(resizeBack);

const [resized] = await clientInstanceGroups.get({
project,
zone,
instanceGroupManager: instanceGroupName,
});
assert.strictEqual(resized.targetSize, 0);
});
});

async function waitZonalOperation(operation) {
for (;;) {
const [getResp] = await operationsClient.get({
const [getResp] = await operationsClient.wait({
project,
zone,
operation: operation.name,
});
if (getResp.status === Status.DONE) {
if (getResp.status === 'DONE') {
// b/191191972
break;
} else {
await new Promise(resolve => setTimeout(resolve, 4000));
Expand All @@ -324,7 +392,8 @@ describe('Compute', () => {
project,
operation: operation.name,
});
if (getResp.status === Status.DONE) {
if (getResp.status === 'DONE') {
// b/191191972
break;
} else {
await new Promise(resolve => setTimeout(resolve, 4000));
Expand Down

0 comments on commit 84ba87f

Please sign in to comment.