-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
notifications.test.js
114 lines (101 loc) · 4.09 KB
/
notifications.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';
const {SecurityCenterClient} = require('@google-cloud/security-center');
const uuidv1 = require('uuid').v1;
const {assert} = require('chai');
const {describe, it, before, after} = require('mocha');
const {execSync} = require('child_process');
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
// TODO(developers): update for your own environment
const organizationId = '1081635000895';
const orgName = 'organizations/' + organizationId;
const pubsubTopic = 'projects/project-a-id/topics/notifications-sample-topic';
describe('Client with Notifications', async () => {
const createConfig = 'notif-config-test-node-create' + uuidv1();
const deleteConfig = 'notif-config-test-node-delete' + uuidv1();
const getConfig = 'notif-config-test-node-get' + uuidv1();
const listConfig = 'notif-config-test-node-list' + uuidv1();
const updateConfig = 'notif-config-test-node-update' + uuidv1();
before(async () => {
const client = new SecurityCenterClient();
async function createNotificationConfig(configId) {
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "^_" }]*/
const [_response] = await client.createNotificationConfig({
parent: orgName,
configId: configId,
notificationConfig: {
description: 'Sample config for node.js',
pubsubTopic: pubsubTopic,
streamingConfig: {filter: 'state = "ACTIVE"'},
},
});
}
await createNotificationConfig(deleteConfig);
await createNotificationConfig(getConfig);
await createNotificationConfig(listConfig);
await createNotificationConfig(updateConfig);
});
after(async () => {
const client = new SecurityCenterClient();
async function deleteNotificationConfig(configId) {
const name = client.organizationNotificationConfigPath(
organizationId,
configId
);
await client.deleteNotificationConfig({name: name});
}
await deleteNotificationConfig(createConfig);
await deleteNotificationConfig(getConfig);
await deleteNotificationConfig(listConfig);
await deleteNotificationConfig(updateConfig);
});
it('client can create config', () => {
const output = exec(
`node v1/createNotificationConfig.js ${organizationId} ${createConfig} ${pubsubTopic}`
);
assert.include(output, createConfig);
assert.match(output, /Notification config creation succeeded/);
assert.notMatch(output, /undefined/);
});
it('client can delete config', () => {
const output = exec(
`node v1/deleteNotificationConfig.js ${organizationId} ${deleteConfig}`
);
assert.include(output, 'Notification config deleted');
assert.notMatch(output, /undefined/);
});
it('client can get config', () => {
const output = exec(
`node v1/getNotificationConfig.js ${organizationId} ${getConfig}`
);
assert.include(output, getConfig);
assert.match(output, /Notification config/);
assert.notMatch(output, /undefined/);
});
it('client can list configs', () => {
const output = exec(`node v1/listNotificationConfigs.js ${organizationId}`);
assert.include(output, listConfig);
assert.match(output, /Received Notification configs/);
assert.notMatch(output, /undefined/);
});
it('client can update configs', () => {
const output = exec(
`node v1/updateNotificationConfig.js ${organizationId} ${updateConfig} ${pubsubTopic}`
);
assert.include(output, updateConfig);
assert.match(output, /notification config update succeeded/);
assert.notMatch(output, /undefined/);
});
});