@@ -26,6 +26,13 @@ const storage = new Storage();
26
26
const bucketName = `asset-nodejs-${ uuid . v4 ( ) } ` ;
27
27
const bucket = storage . bucket ( bucketName ) ;
28
28
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
+
29
36
const Compute = require ( '@google-cloud/compute' ) ;
30
37
const zone = new Compute ( ) . zone ( 'us-central1-c' ) ;
31
38
const vmName = `asset-nodejs-${ uuid . v4 ( ) } ` ;
@@ -49,11 +56,14 @@ const delay = async test => {
49
56
describe ( 'quickstart sample tests' , ( ) => {
50
57
before ( async ( ) => {
51
58
await bucket . create ( ) ;
59
+ await bigquery . createDataset ( datasetId , options ) ;
60
+ await bigquery . dataset ( datasetId ) . exists ( ) ;
52
61
[ vm ] = await zone . createVM ( vmName , { os : 'ubuntu' } ) ;
53
62
} ) ;
54
63
55
64
after ( async ( ) => {
56
65
await bucket . delete ( ) ;
66
+ await bigquery . dataset ( datasetId ) . delete ( { force : true } ) . catch ( console . warn ) ;
57
67
await vm . delete ( ) ;
58
68
} ) ;
59
69
@@ -99,4 +109,41 @@ describe('quickstart sample tests', () => {
99
109
const stdout = execSync ( `node listAssets ${ assetType } ` ) ;
100
110
assert . include ( stdout , assetType ) ;
101
111
} ) ;
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
+ } ) ;
102
149
} ) ;
0 commit comments