diff --git a/asset/snippets/test/asset.test.js b/asset/snippets/test/asset.test.js index fa49f78f98..9cb0e77046 100644 --- a/asset/snippets/test/asset.test.js +++ b/asset/snippets/test/asset.test.js @@ -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 = 2000; + 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); }); diff --git a/asset/snippets/test/orgPolicyAnalyzer.test.js b/asset/snippets/test/orgPolicyAnalyzer.test.js index a922e14eaa..4adbde6a62 100644 --- a/asset/snippets/test/orgPolicyAnalyzer.test.js +++ b/asset/snippets/test/orgPolicyAnalyzer.test.js @@ -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'); @@ -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';