1414
1515'use strict' ;
1616
17- const { assert } = require ( 'chai' ) ;
18- const cp = require ( 'child_process' ) ;
19- const { v4 : uuidv4 } = require ( 'uuid' ) ;
20- const { ModelArmorClient } = require ( '@google-cloud/modelarmor' ) . v1 ;
21- const { DlpServiceClient } = require ( '@google-cloud/dlp' ) ;
17+ const { assert} = require ( 'chai' ) ;
18+ const { v4 : uuidv4 } = require ( 'uuid' ) ;
19+ const { ModelArmorClient} = require ( '@google-cloud/modelarmor' ) . v1 ;
20+ const { DlpServiceClient} = require ( '@google-cloud/dlp' ) ;
2221
2322let projectId ;
2423const locationId = process . env . GCLOUD_LOCATION || 'us-central1' ;
@@ -30,7 +29,6 @@ const options = {
3029
3130const client = new ModelArmorClient ( options ) ;
3231const templateIdPrefix = `test-template-${ uuidv4 ( ) . substring ( 0 , 8 ) } ` ;
33- const execSync = cmd => cp . execSync ( cmd , { encoding : 'utf-8' } ) ;
3432
3533let emptyTemplateId ;
3634let basicTemplateId ;
@@ -79,15 +77,19 @@ async function deleteTemplate(templateName) {
7977 }
8078}
8179
80+ // eslint-disable-next-line no-unused-vars
8281async function disableFloorSettings ( ) {
8382 try {
83+ // Create global client
84+ const global_client = new ModelArmorClient ( ) ;
85+
8486 // Disable project floor settings
85- const [ projectFloorSettings ] = await client . getFloorSetting ( {
87+ const [ projectFloorSettings ] = await global_client . getFloorSetting ( {
8688 name : `projects/${ projectId } /locations/global/floorSetting` ,
8789 } ) ;
8890
8991 if ( projectFloorSettings . enableFloorSettingEnforcement ) {
90- const [ updatedProjectSettings ] = await client . updateFloorSetting ( {
92+ const [ updatedProjectSettings ] = await global_client . updateFloorSetting ( {
9193 floorSetting : {
9294 name : `projects/${ projectId } /locations/global/floorSetting` ,
9395 enableFloorSettingEnforcement : false ,
@@ -104,12 +106,12 @@ async function disableFloorSettings() {
104106
105107 // Disable folder floor settings if folderId is available
106108 if ( folderId ) {
107- const [ folderFloorSettings ] = await client . getFloorSetting ( {
109+ const [ folderFloorSettings ] = await global_client . getFloorSetting ( {
108110 name : `folders/${ folderId } /locations/global/floorSetting` ,
109111 } ) ;
110112
111113 if ( folderFloorSettings . enableFloorSettingEnforcement ) {
112- const [ updatedFolderSettings ] = await client . updateFloorSetting ( {
114+ const [ updatedFolderSettings ] = await global_client . updateFloorSetting ( {
113115 floorSetting : {
114116 name : `folders/${ folderId } /locations/global/floorSetting` ,
115117 enableFloorSettingEnforcement : false ,
@@ -127,12 +129,12 @@ async function disableFloorSettings() {
127129
128130 // Disable organization floor settings if organizationId is available
129131 if ( organizationId ) {
130- const [ orgFloorSettings ] = await client . getFloorSetting ( {
132+ const [ orgFloorSettings ] = await global_client . getFloorSetting ( {
131133 name : `organizations/${ organizationId } /locations/global/floorSetting` ,
132134 } ) ;
133135
134136 if ( orgFloorSettings . enableFloorSettingEnforcement ) {
135- const [ updatedOrgSettings ] = await client . updateFloorSetting ( {
137+ const [ updatedOrgSettings ] = await global_client . updateFloorSetting ( {
136138 floorSetting : {
137139 name : `organizations/${ organizationId } /locations/global/floorSetting` ,
138140 enableFloorSettingEnforcement : false ,
@@ -369,12 +371,10 @@ describe('Model Armor tests', () => {
369371
370372 after ( async ( ) => {
371373 for ( const templateName of templatesToDelete ) {
372-
373- // TODO: Enable clean up once tests are enabled.
374+ // TODO(b/424365799): Uncomment below code once the mentioned issue is resolved
374375 // Disable floor settings to restore original state
375376 // await disableFloorSettings();
376377
377-
378378 await deleteTemplate ( templateName ) ;
379379 }
380380
@@ -383,60 +383,58 @@ describe('Model Armor tests', () => {
383383
384384 // =================== Floor Settings Tests ===================
385385
386- // TODO: Enable these tests once floor settings API issue is resolved.
386+ // TODO(b/424365799) : Enable below tests once the mentioned issue is resolved
387387
388388 it . skip ( 'should get organization floor settings' , ( ) => {
389- const output = execSync (
390- `node snippets/getOrganizationFloorSettings.js ${ organizationId } `
391- ) . toString ( ) ;
389+ const getOrganizationFloorSettings = require ( '../snippets/getOrganizationFloorSettings' ) ;
390+
391+ const output = getOrganizationFloorSettings ( organizationId ) . toString ( ) ;
392+
392393 const expectedName = `organizations/${ organizationId } /locations/global/floorSetting` ;
393394 assert . match ( output , new RegExp ( expectedName . replace ( / \/ / g, '\\/' ) ) ) ;
394395 } ) ;
395396
396397 it . skip ( 'should get folder floor settings' , ( ) => {
397- const output = execSync (
398- `node snippets/getFolderFloorSettings.js ${ folderId } `
399- ) . toString ( ) ;
398+ const getFolderFloorSettings = require ( '../snippets/getFolderFloorSettings' ) ;
399+
400+ const output = getFolderFloorSettings ( folderId ) . toString ( ) ;
400401
401402 // Check for expected name format in output
402403 const expectedName = `folders/${ folderId } /locations/global/floorSetting` ;
403404 assert . match ( output , new RegExp ( expectedName . replace ( / \/ / g, '\\/' ) ) ) ;
404405 } ) ;
405406
406407 it . skip ( 'should get project floor settings' , ( ) => {
407- const output = execSync (
408- `node snippets/getProjectFloorSettings.js ${ projectId } `
409- ) . toString ( ) ;
408+ const getProjectFloorSettings = require ( '../snippets/getProjectFloorSettings' ) ;
409+
410+ const output = getProjectFloorSettings ( projectId ) . toString ( ) ;
410411
411412 // Check for expected name format in output
412413 const expectedName = `projects/${ projectId } /locations/global/floorSetting` ;
413414 assert . match ( output , new RegExp ( expectedName . replace ( / \/ / g, '\\/' ) ) ) ;
414415 } ) ;
415416
416417 it . skip ( 'should update organization floor settings' , ( ) => {
417- const output = execSync (
418- `node snippets/updateOrganizationFloorSettings.js ${ organizationId } `
419- ) . toString ( ) ;
418+ const updateOrganizationFloorSettings = require ( '../snippets/updateOrganizationFloorSettings' ) ;
419+ const output = updateOrganizationFloorSettings ( organizationId ) . toString ( ) ;
420420 // Check that the update was performed
421421 assert . match ( output , / U p d a t e d o r g a n i z a t i o n f l o o r s e t t i n g s / ) ;
422422 // Check that the response contains enableFloorSettingEnforcement=true
423423 assert . match ( output , / e n a b l e F l o o r S e t t i n g E n f o r c e m e n t : \s * t r u e / ) ;
424424 } ) ;
425425
426426 it . skip ( 'should update folder floor settings' , ( ) => {
427- const output = execSync (
428- `node snippets/updateFolderFloorSettings.js ${ folderId } `
429- ) . toString ( ) ;
427+ const updateFolderFloorSettings = require ( '../snippets/updateFolderFloorSettings' ) ;
428+ const output = updateFolderFloorSettings ( folderId ) . toString ( ) ;
430429 // Check that the update was performed
431430 assert . match ( output , / U p d a t e d f o l d e r f l o o r s e t t i n g s / ) ;
432431 // Check that the response contains enableFloorSettingEnforcement=true
433432 assert . match ( output , / e n a b l e F l o o r S e t t i n g E n f o r c e m e n t : \s * t r u e / ) ;
434433 } ) ;
435434
436435 it . skip ( 'should update project floor settings' , ( ) => {
437- const output = execSync (
438- `node snippets/updateProjectFloorSettings.js ${ projectId } `
439- ) . toString ( ) ;
436+ const updateProjectFloorSettings = require ( '../snippets/updateProjectFloorSettings' ) ;
437+ const output = updateProjectFloorSettings ( projectId ) . toString ( ) ;
440438 // Check that the update was performed
441439 assert . match ( output , / U p d a t e d p r o j e c t f l o o r s e t t i n g s / ) ;
442440 // Check that the response contains enableFloorSettingEnforcement=true
@@ -999,4 +997,4 @@ describe('Model Armor tests', () => {
999997 'NO_MATCH_FOUND'
1000998 ) ;
1001999 } ) ;
1002- } ) ;
1000+ } ) ;
0 commit comments