Skip to content

Commit f2ce80b

Browse files
vijaykanthmiennae
authored andcommitted
Address comments by bot:
1 parent 1b4dd70 commit f2ce80b

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

security-center/snippets/system-test/v1/notifications.test.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ const organizationId = '1081635000895';
2626
const orgName = 'organizations/' + organizationId;
2727
const pubsubTopic = 'projects/project-a-id/topics/notifications-sample-topic';
2828

29+
async function waitForConfig(client, configId) {
30+
const maxRetries = 10;
31+
const retryDelay = 1000; // 1 second
32+
let retries = 0;
33+
34+
while (retries < maxRetries) {
35+
try {
36+
const name = client.organizationNotificationConfigPath(organizationId, configId);
37+
const [config] = await client.getNotificationConfig({name});
38+
if (config) return;
39+
} catch (err) {
40+
// Ignore "not found" errors
41+
if (err.code !== 404) throw err;
42+
}
43+
retries++;
44+
await new Promise(resolve => setTimeout(resolve, retryDelay));
45+
}
46+
47+
throw new Error(`Timeout waiting for config ${configId} to be available`);
48+
}
49+
2950
describe('Client with Notifications', async () => {
3051
const createConfig = 'notif-config-test-node-create' + uuidv1();
3152
const deleteConfig = 'notif-config-test-node-delete' + uuidv1();
@@ -48,17 +69,24 @@ describe('Client with Notifications', async () => {
4869
},
4970
});
5071
} catch (err) {
51-
console.error(`Error creating config ${configId}:`, err.message);
72+
if (err.code === 400) {
73+
console.error(`Invalid input for config ${configId}:`, err.message);
74+
} else if (err.code === 503) {
75+
console.error(`Service unavailable when creating config ${configId}:`, err.message);
76+
} else {
77+
console.error(`Unexpected error creating config ${configId}:`, err.message);
78+
}
5279
}
5380
}
5481

5582
await createNotificationConfig(deleteConfig);
56-
await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay
83+
await waitForConfig(client, deleteConfig);
5784
await createNotificationConfig(getConfig);
58-
await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay
85+
await waitForConfig(client, getConfig);
5986
await createNotificationConfig(listConfig);
60-
await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay
87+
await waitForConfig(client, listConfig);
6188
await createNotificationConfig(updateConfig);
89+
await waitForConfig(client, updateConfig);
6290
});
6391

6492
after(async () => {
@@ -71,16 +99,22 @@ describe('Client with Notifications', async () => {
7199
);
72100
await client.deleteNotificationConfig({name: name});
73101
} catch (err) {
74-
console.error(`Error deleting config ${configId}:`, err.message);
102+
if (err.code === 404) {
103+
console.warn(`Config ${configId} not found during deletion:`, err.message);
104+
} else if (err.code === 503) {
105+
console.error(`Service unavailable when deleting config ${configId}:`, err.message);
106+
} else {
107+
console.error(`Unexpected error deleting config ${configId}:`, err.message);
108+
}
75109
}
76110
}
77111

78112
await deleteNotificationConfig(createConfig);
79-
await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay
113+
await waitForConfig(client, createConfig);
80114
await deleteNotificationConfig(getConfig);
81-
await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay
115+
await waitForConfig(client, getConfig);
82116
await deleteNotificationConfig(listConfig);
83-
await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay
117+
await waitForConfig(client, listConfig);
84118
await deleteNotificationConfig(updateConfig);
85119
});
86120

security-center/snippets/v2/addSecurityMarks.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ function main(assetName = 'full asset path to add marks to') {
2727

2828
async function addSecurityMarks() {
2929
// assetName is the full resource path for the asset to update.
30-
/*
31-
* TODO(developer): Uncomment the following lines
32-
*/
3330
// Specify the value of 'assetName' in one of the following formats:
3431
// `organizations/${org-id}/assets/${asset-id}`;
3532
// `projects/${project-id}/assets/${asset-id}`;
@@ -44,7 +41,7 @@ function main(assetName = 'full asset path to add marks to') {
4441
updateMask: {paths: ['marks.key_a', 'marks.key_b']},
4542
});
4643

47-
console.log('New marks: %', newMarks);
44+
console.log('New marks: %j', newMarks);
4845
}
4946
addSecurityMarks();
5047
// [END securitycenter_add_security_marks_v2]

security-center/snippets/v2/deleteAssetsSecurityMarks.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ function main(assetName = 'full asset path to add marks to') {
2727

2828
async function deleteSecurityMarks() {
2929
// assetName is the full resource path for the asset to update.
30-
/*
31-
* TODO(developer): Uncomment the following lines
32-
*/
3330
// Specify the value of 'assetName' in one of the following formats:
3431
// `organizations/${org-id}/assets/${asset-id}`;
3532
// `projects/${project-id}/assets/${asset-id}`;

0 commit comments

Comments
 (0)