Skip to content

Commit 040ade4

Browse files
committed
chore(modelarmor): added floor settings tests and marked as skip for now
1 parent 595f2e9 commit 040ade4

File tree

1 file changed

+147
-6
lines changed

1 file changed

+147
-6
lines changed

model-armor/test/modelarmor.test.js

Lines changed: 147 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@
1414

1515
'use strict';
1616

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');
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');
2122

2223
let projectId;
2324
const locationId = process.env.GCLOUD_LOCATION || 'us-central1';
25+
const folderId = process.env.MA_FOLDER_ID;
26+
const organizationId = process.env.MA_ORG_ID;
2427
const options = {
2528
apiEndpoint: `modelarmor.${locationId}.rep.googleapis.com`,
2629
};
2730

2831
const client = new ModelArmorClient(options);
2932
const templateIdPrefix = `test-template-${uuidv4().substring(0, 8)}`;
33+
const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' });
3034

3135
let emptyTemplateId;
3236
let basicTemplateId;
@@ -75,6 +79,79 @@ async function deleteTemplate(templateName) {
7579
}
7680
}
7781

82+
async function disableFloorSettings() {
83+
try {
84+
// Disable project floor settings
85+
const [projectFloorSettings] = await client.getFloorSetting({
86+
name: `projects/${projectId}/locations/global/floorSetting`,
87+
});
88+
89+
if (projectFloorSettings.enableFloorSettingEnforcement) {
90+
const [updatedProjectSettings] = await client.updateFloorSetting({
91+
floorSetting: {
92+
name: `projects/${projectId}/locations/global/floorSetting`,
93+
enableFloorSettingEnforcement: false,
94+
},
95+
updateMask: {
96+
paths: ['enable_floor_setting_enforcement'],
97+
},
98+
});
99+
console.log(
100+
'Disabled project floor settings:',
101+
updatedProjectSettings.name
102+
);
103+
}
104+
105+
// Disable folder floor settings if folderId is available
106+
if (folderId) {
107+
const [folderFloorSettings] = await client.getFloorSetting({
108+
name: `folders/${folderId}/locations/global/floorSetting`,
109+
});
110+
111+
if (folderFloorSettings.enableFloorSettingEnforcement) {
112+
const [updatedFolderSettings] = await client.updateFloorSetting({
113+
floorSetting: {
114+
name: `folders/${folderId}/locations/global/floorSetting`,
115+
enableFloorSettingEnforcement: false,
116+
},
117+
updateMask: {
118+
paths: ['enable_floor_setting_enforcement'],
119+
},
120+
});
121+
console.log(
122+
'Disabled folder floor settings:',
123+
updatedFolderSettings.name
124+
);
125+
}
126+
}
127+
128+
// Disable organization floor settings if organizationId is available
129+
if (organizationId) {
130+
const [orgFloorSettings] = await client.getFloorSetting({
131+
name: `organizations/${organizationId}/locations/global/floorSetting`,
132+
});
133+
134+
if (orgFloorSettings.enableFloorSettingEnforcement) {
135+
const [updatedOrgSettings] = await client.updateFloorSetting({
136+
floorSetting: {
137+
name: `organizations/${organizationId}/locations/global/floorSetting`,
138+
enableFloorSettingEnforcement: false,
139+
},
140+
updateMask: {
141+
paths: ['enable_floor_setting_enforcement'],
142+
},
143+
});
144+
console.log(
145+
'Disabled organization floor settings:',
146+
updatedOrgSettings.name
147+
);
148+
}
149+
}
150+
} catch (error) {
151+
console.error('Error disabling floor settings:', error);
152+
}
153+
}
154+
78155
// Helper function to create DLP template.
79156
async function createDlpTemplates() {
80157
try {
@@ -292,6 +369,12 @@ describe('Model Armor tests', () => {
292369

293370
after(async () => {
294371
for (const templateName of templatesToDelete) {
372+
373+
// TODO: Enable clean up once tests are enabled.
374+
// Disable floor settings to restore original state
375+
// await disableFloorSettings();
376+
377+
295378
await deleteTemplate(templateName);
296379
}
297380

@@ -300,7 +383,65 @@ describe('Model Armor tests', () => {
300383

301384
// =================== Floor Settings Tests ===================
302385

303-
// TODO: Add tests for floor settings once the floor setting API issues are resolved.
386+
// TODO: Enable these tests once floor settings API issue is resolved.
387+
388+
it.skip('should get organization floor settings', () => {
389+
const output = execSync(
390+
`node snippets/getOrganizationFloorSettings.js ${organizationId}`
391+
).toString();
392+
const expectedName = `organizations/${organizationId}/locations/global/floorSetting`;
393+
assert.match(output, new RegExp(expectedName.replace(/\//g, '\\/')));
394+
});
395+
396+
it.skip('should get folder floor settings', () => {
397+
const output = execSync(
398+
`node snippets/getFolderFloorSettings.js ${folderId}`
399+
).toString();
400+
401+
// Check for expected name format in output
402+
const expectedName = `folders/${folderId}/locations/global/floorSetting`;
403+
assert.match(output, new RegExp(expectedName.replace(/\//g, '\\/')));
404+
});
405+
406+
it.skip('should get project floor settings', () => {
407+
const output = execSync(
408+
`node snippets/getProjectFloorSettings.js ${projectId}`
409+
).toString();
410+
411+
// Check for expected name format in output
412+
const expectedName = `projects/${projectId}/locations/global/floorSetting`;
413+
assert.match(output, new RegExp(expectedName.replace(/\//g, '\\/')));
414+
});
415+
416+
it.skip('should update organization floor settings', () => {
417+
const output = execSync(
418+
`node snippets/updateOrganizationFloorSettings.js ${organizationId}`
419+
).toString();
420+
// Check that the update was performed
421+
assert.match(output, /Updated organization floor settings/);
422+
// Check that the response contains enableFloorSettingEnforcement=true
423+
assert.match(output, /enableFloorSettingEnforcement:\s*true/);
424+
});
425+
426+
it.skip('should update folder floor settings', () => {
427+
const output = execSync(
428+
`node snippets/updateFolderFloorSettings.js ${folderId}`
429+
).toString();
430+
// Check that the update was performed
431+
assert.match(output, /Updated folder floor settings/);
432+
// Check that the response contains enableFloorSettingEnforcement=true
433+
assert.match(output, /enableFloorSettingEnforcement:\s*true/);
434+
});
435+
436+
it.skip('should update project floor settings', () => {
437+
const output = execSync(
438+
`node snippets/updateProjectFloorSettings.js ${projectId}`
439+
).toString();
440+
// Check that the update was performed
441+
assert.match(output, /Updated project floor settings/);
442+
// Check that the response contains enableFloorSettingEnforcement=true
443+
assert.match(output, /enableFloorSettingEnforcement:\s*true/);
444+
});
304445

305446
// =================== Template Creation Tests ===================
306447

@@ -858,4 +999,4 @@ describe('Model Armor tests', () => {
858999
'NO_MATCH_FOUND'
8591000
);
8601001
});
861-
});
1002+
});

0 commit comments

Comments
 (0)