-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expand file tree
/
Copy pathconfig.test.ts
More file actions
136 lines (128 loc) · 3.78 KB
/
Copy pathconfig.test.ts
File metadata and controls
136 lines (128 loc) · 3.78 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { configSchema } from './config';
describe('config validation', () => {
test('alerting defaults', () => {
const config: Record<string, unknown> = {};
expect(configSchema.validate(config)).toMatchInlineSnapshot(`
Object {
"alertsService": Object {
"coordinateInstallation": true,
"totalFieldsLimit": 2800,
},
"cancelAlertsOnRuleTimeout": true,
"enableFrameworkAlerts": true,
"healthCheck": Object {
"interval": "60m",
},
"invalidateApiKeysTask": Object {
"interval": "5m",
"removalDelay": "1h",
},
"ruleChangeTracking": Object {
"scope": Array [
"security",
],
},
"rules": Object {
"apiKeyType": "es",
"maxScheduledPerMinute": 32000,
"minimumScheduleInterval": Object {
"enforce": false,
"value": "1m",
},
"run": Object {
"actions": Object {
"max": 100000,
},
"alerts": Object {
"max": 1000,
},
},
},
"rulesSettings": Object {
"cacheInterval": 60000,
"enabled": true,
},
}
`);
});
describe('rules.minimumScheduleInterval.value', () => {
test('allows 1d as a value', () => {
const config: Record<string, unknown> = {
rules: {
minimumScheduleInterval: {
value: '1d',
},
},
};
const validatedConfig = configSchema.validate(config);
expect(validatedConfig.rules.minimumScheduleInterval.value).toMatchInlineSnapshot(`"1d"`);
});
test(`doesn't allow 2d as a value`, () => {
const config: Record<string, unknown> = {
rules: {
minimumScheduleInterval: {
value: '2d',
},
},
};
expect(() => configSchema.validate(config)).toThrowErrorMatchingInlineSnapshot(
`"[rules.minimumScheduleInterval.value]: duration cannot exceed one day"`
);
});
test(`doesn't allow 25h as a value`, () => {
const config: Record<string, unknown> = {
rules: {
minimumScheduleInterval: {
value: '25h',
},
},
};
expect(() => configSchema.validate(config)).toThrowErrorMatchingInlineSnapshot(
`"[rules.minimumScheduleInterval.value]: duration cannot exceed one day"`
);
});
});
describe('rules.run.actions.max', () => {
test('allows 100000 as a value', () => {
const config: Record<string, unknown> = {
rules: {
run: {
actions: {
max: 100000,
},
},
},
};
const validatedConfig = configSchema.validate(config);
expect(validatedConfig.rules.run.actions.max).toMatchInlineSnapshot(`100000`);
});
test(`doesn't allow 100001 as a value`, () => {
const config: Record<string, unknown> = {
rules: {
run: {
actions: {
max: 100001,
},
},
},
};
expect(() => configSchema.validate(config)).toThrowErrorMatchingInlineSnapshot(
`"[rules.run.actions.max]: Value must be equal to or lower than [100000]."`
);
});
});
test('maxScheduledPerMinute allows more than 32000', () => {
const config: Record<string, unknown> = {
rules: {
maxScheduledPerMinute: 50000,
},
};
expect(() => configSchema.validate(config)).not.toThrow();
});
});