-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild-command.spec.ts
More file actions
215 lines (189 loc) · 7.7 KB
/
Copy pathbuild-command.spec.ts
File metadata and controls
215 lines (189 loc) · 7.7 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import { buildInstallArgs, buildMysqlPrepArgs, Services } from './build-command';
const BASE_ARGS = [
'--base-url=http://localhost/',
'--admin-user=admin',
'--admin-password=admin123',
'--admin-email=admin@example.com',
'--admin-firstname=Admin',
'--admin-lastname=User',
'--backend-frontname=admin',
];
const MYSQL_SERVICE = {
image: 'mysql:8.4',
env: {
MYSQL_DATABASE: 'magento_integration_tests',
MYSQL_USER: 'user',
MYSQL_PASSWORD: 'password',
MYSQL_ROOT_PASSWORD: 'rootpassword',
},
ports: ['3306:3306'],
options: '--health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3',
};
const MARIADB_SERVICE = {
image: 'mariadb:11.4',
env: {
MYSQL_DATABASE: 'magento_integration_tests',
MYSQL_USER: 'user',
MYSQL_PASSWORD: 'password',
MYSQL_ROOT_PASSWORD: 'rootpassword',
},
ports: ['3306:3306'],
options: '--health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3',
};
const DB_ARGS = [
'--db-host=127.0.0.1:3306',
'--db-name=magento_integration_tests',
'--db-user=user',
'--db-password=password',
];
const MYSQL_ARGS = DB_ARGS;
const OPENSEARCH_ARGS = [
'--search-engine=opensearch',
'--opensearch-host=localhost',
'--opensearch-port=9200',
];
const RABBITMQ_ARGS = [
'--amqp-host=localhost',
'--amqp-port=5672',
'--amqp-user=guest',
'--amqp-password=guest',
];
const CACHE_ARGS = [
'--session-save=redis',
'--session-save-redis-host=localhost',
'--session-save-redis-port=6379',
'--cache-backend=redis',
'--cache-backend-redis-server=localhost',
'--cache-backend-redis-port=6379',
];
describe('buildInstallArgs', () => {
describe('base args', () => {
it('returns only base args when services is null', () => {
expect(buildInstallArgs(null)).toEqual(BASE_ARGS);
});
it('returns only base args when services is empty', () => {
expect(buildInstallArgs({})).toEqual(BASE_ARGS);
});
});
describe('database', () => {
it('adds db flags when mysql service is present', () => {
const services: Services = { mysql: MYSQL_SERVICE };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...DB_ARGS]);
});
it('adds db flags when mariadb service is present', () => {
const services: Services = { mariadb: MARIADB_SERVICE };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...DB_ARGS]);
});
it('prefers mariadb over mysql when both are present', () => {
const services: Services = {
mariadb: MARIADB_SERVICE,
mysql: { ...MYSQL_SERVICE, ports: ['3307:3306'] },
};
const args = buildInstallArgs(services);
expect(args).toContain('--db-host=127.0.0.1:3306');
expect(args).not.toContain('--db-host=127.0.0.1:3307');
});
});
describe('search engine', () => {
it('adds opensearch flags when opensearch service is present', () => {
const services: Services = { opensearch: { image: 'opensearchproject/opensearch:2.19.1' } };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...OPENSEARCH_ARGS]);
});
it('adds elasticsearch7 flags for an elasticsearch 7.x image', () => {
const services: Services = { elasticsearch: { image: 'elasticsearch:7.17.0' } };
expect(buildInstallArgs(services)).toEqual([
...BASE_ARGS,
'--search-engine=elasticsearch7',
'--elasticsearch-host=localhost',
'--elasticsearch-port=9200',
]);
});
it('adds elasticsearch8 flags for an elasticsearch 8.x image', () => {
const services: Services = { elasticsearch: { image: 'elasticsearch:8.11.4' } };
expect(buildInstallArgs(services)).toEqual([
...BASE_ARGS,
'--search-engine=elasticsearch8',
'--elasticsearch-host=localhost',
'--elasticsearch-port=9200',
]);
});
it('prefers opensearch over elasticsearch when both are present', () => {
const services: Services = {
opensearch: { image: 'opensearchproject/opensearch:2.19.1' },
elasticsearch: { image: 'elasticsearch:8.11.4' },
};
const args = buildInstallArgs(services);
expect(args).toContain('--search-engine=opensearch');
expect(args.some(a => a.startsWith('--search-engine=elasticsearch'))).toBe(false);
});
});
describe('rabbitmq', () => {
it('adds amqp flags when rabbitmq service is present', () => {
const services: Services = { rabbitmq: { image: 'rabbitmq:4.0-management' } };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...RABBITMQ_ARGS]);
});
});
describe('cache / session', () => {
it('adds redis cache flags when redis service is present', () => {
const services: Services = { redis: { image: 'redis:7.2' } };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...CACHE_ARGS]);
});
it('adds redis cache flags when valkey service is present', () => {
const services: Services = { valkey: { image: 'valkey:8.0' } };
expect(buildInstallArgs(services)).toEqual([...BASE_ARGS, ...CACHE_ARGS]);
});
it('adds cache flags once when both valkey and redis are present', () => {
const services: Services = {
valkey: { image: 'valkey:8.0' },
redis: { image: 'redis:7.2' },
};
const args = buildInstallArgs(services);
expect(args.filter(a => a === '--session-save=redis')).toHaveLength(1);
});
});
describe('buildMysqlPrepArgs', () => {
it('uses root password and port from mysql service config', () => {
expect(buildMysqlPrepArgs(MYSQL_SERVICE)).toEqual([
'-h127.0.0.1',
'--port=3306',
'-uroot',
'-prootpassword',
'-e', 'SET GLOBAL log_bin_trust_function_creators = 1;',
]);
});
it('uses root password and port from mariadb service config', () => {
expect(buildMysqlPrepArgs(MARIADB_SERVICE)).toEqual([
'-h127.0.0.1',
'--port=3306',
'-uroot',
'-prootpassword',
'-e', 'SET GLOBAL log_bin_trust_function_creators = 1;',
]);
});
it('falls back to default port when ports is absent', () => {
const args = buildMysqlPrepArgs({ image: 'mysql:8.4' });
expect(args).toContain('--port=3306');
});
it('falls back to default root password when env is absent', () => {
const args = buildMysqlPrepArgs({ image: 'mysql:8.4' });
expect(args).toContain('-prootpassword');
});
});
describe('all services', () => {
it('adds all flags when all services are present', () => {
const services: Services = {
mysql: MYSQL_SERVICE,
opensearch: { image: 'opensearchproject/opensearch:2.19.1' },
rabbitmq: { image: 'rabbitmq:4.0-management' },
valkey: { image: 'valkey:8.0' },
};
expect(buildInstallArgs(services)).toEqual([
...BASE_ARGS,
...MYSQL_ARGS,
...OPENSEARCH_ARGS,
...RABBITMQ_ARGS,
...CACHE_ARGS,
]);
});
});
});