Skip to content

Commit c3f6057

Browse files
CopilotBlankll
andcommitted
Add unit tests for RDS and ES Serverless types
Co-authored-by: Blankll <28639911+Blankll@users.noreply.github.com>
1 parent 72fa483 commit c3f6057

File tree

2 files changed

+543
-0
lines changed

2 files changed

+543
-0
lines changed
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
import {
2+
databaseToEsConfig,
3+
extractEsDefinition,
4+
} from '../../../src/stack/aliyunStack/esServerlessTypes';
5+
import { DatabaseDomain, DatabaseEnum, DatabaseVersionEnum } from '../../../src/types';
6+
7+
describe('EsServerlessTypes', () => {
8+
describe('databaseToEsConfig', () => {
9+
it('should convert database domain to ES config for Search 7.10', () => {
10+
const database: DatabaseDomain = {
11+
key: 'test_es',
12+
name: 'test-es-search',
13+
type: DatabaseEnum.ELASTICSEARCH_SERVERLESS,
14+
version: DatabaseVersionEnum['ES_SEARCH_7.10'],
15+
security: {
16+
basicAuth: {
17+
password: 'TestPass123!',
18+
},
19+
},
20+
network: {
21+
type: 'PUBLIC',
22+
ingressRules: ['10.0.0.0/8', '192.168.0.0/16'],
23+
},
24+
cu: {
25+
min: 2,
26+
max: 8,
27+
},
28+
storage: {
29+
min: 20,
30+
},
31+
};
32+
33+
const result = databaseToEsConfig(database);
34+
35+
expect(result.AppName).toBe('test-es-search');
36+
expect(result.AppVersion).toBe('7.10');
37+
expect(result.Authentication?.BasicAuth?.[0].Password).toBe('TestPass123!');
38+
expect(result.QuotaInfo.AppType).toBe('STANDARD');
39+
expect(result.QuotaInfo.MinCu).toBe(2);
40+
expect(result.Description).toBe('Elasticsearch serverless app: test-es-search');
41+
});
42+
43+
it('should configure network for PUBLIC access', () => {
44+
const database: DatabaseDomain = {
45+
key: 'test_es',
46+
name: 'test-es',
47+
type: DatabaseEnum.ELASTICSEARCH_SERVERLESS,
48+
version: DatabaseVersionEnum['ES_SEARCH_7.10'],
49+
security: {
50+
basicAuth: {
51+
password: 'TestPass123!',
52+
},
53+
},
54+
network: {
55+
type: 'PUBLIC',
56+
ingressRules: ['10.0.0.0/8'],
57+
},
58+
cu: {
59+
min: 2,
60+
max: 8,
61+
},
62+
storage: {
63+
min: 20,
64+
},
65+
};
66+
67+
const result = databaseToEsConfig(database);
68+
69+
expect(result.Network).toBeDefined();
70+
expect(result.Network).toHaveLength(2);
71+
expect(result.Network?.[0].Type).toBe('PUBLIC_KIBANA');
72+
expect(result.Network?.[0].Enabled).toBe(true);
73+
expect(result.Network?.[0].WhiteIpGroup?.[0].Ips).toEqual(['10.0.0.0/8']);
74+
expect(result.Network?.[1].Type).toBe('PUBLIC_ES');
75+
});
76+
77+
it('should not configure network for PRIVATE access', () => {
78+
const database: DatabaseDomain = {
79+
key: 'test_es',
80+
name: 'test-es',
81+
type: DatabaseEnum.ELASTICSEARCH_SERVERLESS,
82+
version: DatabaseVersionEnum['ES_SEARCH_7.10'],
83+
security: {
84+
basicAuth: {
85+
password: 'TestPass123!',
86+
},
87+
},
88+
network: {
89+
type: 'PRIVATE',
90+
ingressRules: [],
91+
},
92+
cu: {
93+
min: 2,
94+
max: 8,
95+
},
96+
storage: {
97+
min: 20,
98+
},
99+
};
100+
101+
const result = databaseToEsConfig(database);
102+
103+
expect(result.Network).toBeUndefined();
104+
});
105+
106+
it('should map Time Series 7.10 correctly', () => {
107+
const database: DatabaseDomain = {
108+
key: 'test_es',
109+
name: 'test-es-ts',
110+
type: DatabaseEnum.ELASTICSEARCH_SERVERLESS,
111+
version: DatabaseVersionEnum['ES_TIME_SERIES_7.10'],
112+
security: {
113+
basicAuth: {
114+
password: 'TestPass123!',
115+
},
116+
},
117+
network: {
118+
type: 'PRIVATE',
119+
ingressRules: [],
120+
},
121+
cu: {
122+
min: 2,
123+
max: 8,
124+
},
125+
storage: {
126+
min: 20,
127+
},
128+
};
129+
130+
const result = databaseToEsConfig(database);
131+
132+
expect(result.AppVersion).toBe('7.10');
133+
expect(result.QuotaInfo.AppType).toBe('TRIAL');
134+
});
135+
136+
it('should throw error for unsupported database type', () => {
137+
const database: DatabaseDomain = {
138+
key: 'test_db',
139+
name: 'test-db',
140+
type: DatabaseEnum.RDS_MYSQL_SERVERLESS,
141+
version: DatabaseVersionEnum['MYSQL_8.0'],
142+
security: {
143+
basicAuth: {
144+
password: 'TestPass123!',
145+
},
146+
},
147+
network: {
148+
type: 'PRIVATE',
149+
ingressRules: [],
150+
},
151+
cu: {
152+
min: 1,
153+
max: 8,
154+
},
155+
storage: {
156+
min: 20,
157+
},
158+
};
159+
160+
expect(() => databaseToEsConfig(database)).toThrow('Unsupported ES database type/version');
161+
});
162+
});
163+
164+
describe('extractEsDefinition', () => {
165+
it('should extract all attributes with null for undefined fields', () => {
166+
const config = {
167+
AppName: 'test-es',
168+
AppVersion: '7.10',
169+
Authentication: {
170+
BasicAuth: [
171+
{
172+
Password: 'TestPass123!',
173+
},
174+
],
175+
},
176+
QuotaInfo: {
177+
AppType: 'STANDARD',
178+
MinCu: 2,
179+
},
180+
Description: 'Test ES app',
181+
Network: [
182+
{
183+
Type: 'PUBLIC_ES',
184+
Enabled: true,
185+
WhiteIpGroup: [
186+
{
187+
GroupName: 'default',
188+
Ips: ['10.0.0.0/8'],
189+
},
190+
],
191+
},
192+
],
193+
};
194+
195+
const definition = extractEsDefinition(config);
196+
197+
expect(definition).toEqual({
198+
appName: 'test-es',
199+
appVersion: '7.10',
200+
authentication: {
201+
basicAuth: [{ password: '***' }],
202+
},
203+
quotaInfo: {
204+
appType: 'STANDARD',
205+
minCu: 2,
206+
},
207+
description: 'Test ES app',
208+
network: [
209+
{
210+
type: 'PUBLIC_ES',
211+
enabled: true,
212+
whiteIpGroup: [
213+
{
214+
groupName: 'default',
215+
ips: ['10.0.0.0/8'],
216+
},
217+
],
218+
},
219+
],
220+
});
221+
});
222+
223+
it('should mask passwords in definition', () => {
224+
const config = {
225+
AppName: 'test-es',
226+
AppVersion: '7.10',
227+
Authentication: {
228+
BasicAuth: [
229+
{
230+
Password: 'SuperSecret123!',
231+
},
232+
],
233+
},
234+
QuotaInfo: {
235+
AppType: 'STANDARD',
236+
MinCu: 2,
237+
},
238+
};
239+
240+
const definition = extractEsDefinition(config);
241+
242+
expect(definition.authentication).toEqual({
243+
basicAuth: [{ password: '***' }],
244+
});
245+
});
246+
247+
it('should handle undefined authentication', () => {
248+
const config = {
249+
AppName: 'test-es',
250+
AppVersion: '7.10',
251+
QuotaInfo: {
252+
AppType: 'STANDARD',
253+
MinCu: 2,
254+
},
255+
};
256+
257+
const definition = extractEsDefinition(config);
258+
259+
expect(definition.authentication).toBeNull();
260+
});
261+
});
262+
});

0 commit comments

Comments
 (0)