@@ -26,6 +26,13 @@ const storage = new Storage();
2626const bucketName = `asset-nodejs-${ uuid . v4 ( ) } ` ;
2727const bucket = storage . bucket ( bucketName ) ;
2828
29+ const { BigQuery} = require ( '@google-cloud/bigquery' ) ;
30+ const bigquery = new BigQuery ( ) ;
31+ const options = {
32+ location : 'US' ,
33+ } ;
34+ const datasetId = `asset_nodejs_${ uuid . v4 ( ) } ` . replace ( / - / gi, '_' ) ;
35+
2936const Compute = require ( '@google-cloud/compute' ) ;
3037const zone = new Compute ( ) . zone ( 'us-central1-c' ) ;
3138const vmName = `asset-nodejs-${ uuid . v4 ( ) } ` ;
@@ -49,11 +56,14 @@ const delay = async test => {
4956describe ( 'quickstart sample tests' , ( ) => {
5057 before ( async ( ) => {
5158 await bucket . create ( ) ;
59+ await bigquery . createDataset ( datasetId , options ) ;
60+ await bigquery . dataset ( datasetId ) . exists ( ) ;
5261 [ vm ] = await zone . createVM ( vmName , { os : 'ubuntu' } ) ;
5362 } ) ;
5463
5564 after ( async ( ) => {
5665 await bucket . delete ( ) ;
66+ await bigquery . dataset ( datasetId ) . delete ( { force : true } ) . catch ( console . warn ) ;
5767 await vm . delete ( ) ;
5868 } ) ;
5969
@@ -99,4 +109,41 @@ describe('quickstart sample tests', () => {
99109 const stdout = execSync ( `node listAssets ${ assetType } ` ) ;
100110 assert . include ( stdout , assetType ) ;
101111 } ) ;
112+
113+ it ( 'should analyze iam policy successfully' , async ( ) => {
114+ const stdout = execSync ( 'node analyzeIamPolicy' ) ;
115+ assert . include ( stdout , '//cloudresourcemanager.googleapis.com/projects' ) ;
116+ } ) ;
117+
118+ it ( 'should analyze iam policy and write analysis results to gcs successfully' , async function ( ) {
119+ this . retries ( 2 ) ;
120+ await delay ( this . test ) ;
121+ const uri = `gs://${ bucketName } /my-analysis.json` ;
122+ execSync ( `node analyzeIamPolicyLongrunningGcs ${ uri } ` ) ;
123+ const file = await bucket . file ( 'my-analysis.json' ) ;
124+ const exists = await file . exists ( ) ;
125+ assert . ok ( exists ) ;
126+ await file . delete ( ) ;
127+ } ) ;
128+
129+ it ( 'should analyze iam policy and write analysis results to bigquery successfully' , async function ( ) {
130+ this . retries ( 2 ) ;
131+ await delay ( this . test ) ;
132+ const tablePrefix = 'analysis_nodejs' ;
133+ execSync (
134+ `node analyzeIamPolicyLongrunningBigquery ${ datasetId } ${ tablePrefix } `
135+ ) ;
136+ const metadataTable = await bigquery
137+ . dataset ( datasetId )
138+ . table ( 'analysis_nodejs_analysis' ) ;
139+ const metadataTable_exists = await metadataTable . exists ( ) ;
140+ assert . ok ( metadataTable_exists ) ;
141+ const resultsTable = await bigquery
142+ . dataset ( datasetId )
143+ . table ( 'analysis_nodejs_analysis_result' ) ;
144+ const resultsTable_exists = await resultsTable . exists ( ) ;
145+ assert . ok ( resultsTable_exists ) ;
146+ await metadataTable . delete ( ) ;
147+ await resultsTable . delete ( ) ;
148+ } ) ;
102149} ) ;
0 commit comments