Skip to content
15 changes: 14 additions & 1 deletion asset/snippets/test/asset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,20 @@ describe('asset sample tests', () => {

it('should list assets successfully', async () => {
const assetType = 'storage.googleapis.com/Bucket';
const stdout = execSync(`node listAssets ${assetType} 'RESOURCE'`);
let waitMs = 60000;
let stdout = '';
for (let retry = 0; retry < 3; retry++) {
try {
await sleep(waitMs);
stdout = execSync(`node listAssets ${assetType} 'RESOURCE'`);
break;
} catch (err) {
if (retry === 2) {
throw err;
}
}
waitMs *= 2;
}
assert.include(stdout, assetType);
});

Expand Down
28 changes: 1 addition & 27 deletions asset/snippets/test/orgPolicyAnalyzer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,15 @@
'use strict';

const {assert} = require('chai');
const {after, before, describe, it} = require('mocha');
const {describe, it} = require('mocha');
const sinon = require('sinon');
const uuid = require('uuid');

const cp = require('child_process');
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const {Storage} = require('@google-cloud/storage');

const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const options = {
location: 'US',
};
const datasetId = `asset_nodejs_${uuid.v4()}`.replace(/-/gi, '_');

const orgId = 'organizations/474566717491'; // This is the id of ipa1.joonix.net, a test organization owned by mdb.cloud-asset-analysis-team@google.com

describe('org policy analyzer sample tests', () => {
let bucket;
let bucketName;

const stubConsole = function () {
sinon.stub(console, 'error');
sinon.stub(console, 'log');
Expand All @@ -49,19 +36,6 @@ describe('org policy analyzer sample tests', () => {
beforeEach(stubConsole);
afterEach(restoreConsole);

before(async () => {
bucketName = `asset-nodejs-${uuid.v4()}`;
bucket = new Storage().bucket(bucketName);
await bucket.create();
await bigquery.createDataset(datasetId, options);
await bigquery.dataset(datasetId).exists();
});

after(async () => {
await bucket.delete();
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
});

it('should analyze org policies successfully', async () => {
const constraint =
'constraints/iam.allowServiceAccountCredentialLifetimeExtension';
Expand Down
Loading