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

Commit

Permalink
tests: add pagination tests (#595)
Browse files Browse the repository at this point in the history
* tests: add pagination tests

* tests: lower max results
  • Loading branch information
georgiyekkert authored Aug 11, 2021
1 parent 371165b commit 28a3b20
Showing 1 changed file with 62 additions and 8 deletions.
70 changes: 62 additions & 8 deletions system-test/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Compute', () => {
region,
});
let presented = false;
for (const item of listResponse.items) {
for (const item of listResponse) {
if (item.name === ADDRESS_NAME) {
presented = true;
}
Expand All @@ -91,17 +91,20 @@ describe('Compute', () => {
'address was not found in list response.'
);

const [aggregatedResponse] = await client.aggregatedList({
const iterable = client.aggregatedListAsync({
project,
region,
});
presented = false;
const arr = aggregatedResponse.items['regions/' + region].addresses;
arr.forEach(address => {
if (address.name === ADDRESS_NAME) {
presented = true;
for await (const [location, addressesObject] of iterable) {
if (location === 'regions/' + region) {
const addresses = addressesObject.addresses;
addresses.forEach(address => {
if (address.name === ADDRESS_NAME) {
presented = true;
}
});
}
});
}
assert.strictEqual(
presented,
true,
Expand Down Expand Up @@ -385,6 +388,57 @@ describe('Compute', () => {
}
}

describe('Pagination', () => {
let client = null;

before(async () => {
client = new compute.AcceleratorTypesClient({fallback: 'rest'});
});

it('Pagination in list response', async () => {
const [listResponse] = await client.list({
project,
zone,
maxResults: 1,
});
let presented = false;
for (const item of listResponse) {
if (item.name === 'nvidia-tesla-t4') {
presented = true;
}
}
assert.strictEqual(
presented,
true,
'accelerator type nvidia-tesla-t4 was not found in list response.'
);
});

it('Pagination in map responses', async function () {
this.timeout(10 * 60 * 1000);
const iterable = client.aggregatedListAsync({
project,
maxResults: 2,
});
let presented = false;
for await (const [location, acceleratorTypesObj] of iterable) {
if (location === 'zones/' + zone) {
const acceleratorTypes = acceleratorTypesObj.acceleratorTypes;
acceleratorTypes.forEach(acceleratorType => {
if (acceleratorType.name === 'nvidia-tesla-t4') {
presented = true;
}
});
}
}
assert.strictEqual(
presented,
true,
'accelerator type nvidia-tesla-t4 was not found in map response.'
);
});
});

async function waitGlobalOperation(operation) {
const globalClient = new compute.GlobalOperationsClient({fallback: 'rest'});
for (;;) {
Expand Down

0 comments on commit 28a3b20

Please sign in to comment.