Skip to content

Commit 6f97d30

Browse files
committed
refactor proxy url in tests
1 parent 90b1e57 commit 6f97d30

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

__tests__/locations/index.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('Locations', () => {
135135
let requests: Array<any> = [];
136136
let proxyServer: Straightforward;
137137
let tlsServer;
138-
let proxyPort: number;
138+
let proxyUrl: string;
139139

140140
beforeAll(async () => {
141141
proxyServer = new Straightforward();
@@ -149,7 +149,8 @@ describe('Locations', () => {
149149
res.setHeader('content-type', 'application/json');
150150
res.end(JSON.stringify({ locations: LOCATIONS }));
151151
});
152-
({ port: proxyPort } = proxyServer.server.address() as AddressInfo);
152+
const server = proxyServer.server.address() as AddressInfo;
153+
proxyUrl = `http://localhost:${server.port}`;
153154
});
154155

155156
afterAll(async () => {
@@ -164,7 +165,7 @@ describe('Locations', () => {
164165
it('enables proxy based on HTTP_PROXY', async () => {
165166
await fakeProjectSetup({ project: { url: server.PREFIX } });
166167
const output = await runLocations(['--auth', apiKey], {
167-
HTTP_PROXY: `http://localhost:${proxyPort}`,
168+
HTTP_PROXY: proxyUrl,
168169
});
169170
expect(output).toContain(`custom location 1`);
170171
expect(requests).toHaveLength(1);
@@ -174,7 +175,7 @@ describe('Locations', () => {
174175
await fakeProjectSetup({ project: { url: server.PREFIX } });
175176
const output = await runLocations(['--auth', apiKey], {
176177
NO_PROXY: '*',
177-
HTTP_PROXY: `http://localhost:${proxyPort}`,
178+
HTTP_PROXY: proxyUrl,
178179
});
179180
expect(output).toContain(`custom location 1`);
180181
expect(requests).toHaveLength(0);
@@ -183,7 +184,7 @@ describe('Locations', () => {
183184
it('enables proxy based on HTTPS_PROXY', async () => {
184185
await fakeProjectSetup({ project: { url: tlsServer.PREFIX } });
185186
const output = await runLocations(['--auth', apiKey], {
186-
HTTPS_PROXY: `http://localhost:${proxyPort}`,
187+
HTTPS_PROXY: proxyUrl,
187188
NODE_TLS_REJECT_UNAUTHORIZED: '0',
188189
});
189190
expect(output).toContain(`custom location 1`);
@@ -196,7 +197,7 @@ describe('Locations', () => {
196197
'--auth',
197198
apiKey,
198199
'--proxy-uri',
199-
`http://localhost:${proxyPort}`,
200+
proxyUrl,
200201
]);
201202
expect(output).toContain(`custom location 1`);
202203
expect(requests).toHaveLength(1);
@@ -205,7 +206,7 @@ describe('Locations', () => {
205206
it('enables proxy based on proxy settings', async () => {
206207
await fakeProjectSetup({
207208
project: { url: server.PREFIX },
208-
proxy: { uri: `http://localhost:${proxyPort}` },
209+
proxy: { uri: proxyUrl },
209210
});
210211
const output = await runLocations(['--auth', apiKey]);
211212
expect(output).toContain(`custom location 1`);

__tests__/push/index.test.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ heartbeat.monitors:
360360
let requests: Array<any> = [];
361361
let proxyServer: Straightforward;
362362
let tlsServer;
363-
let proxyPort: number;
363+
let proxyUrl: string;
364364

365365
beforeAll(async () => {
366366
proxyServer = new Straightforward();
@@ -372,7 +372,8 @@ heartbeat.monitors:
372372
tlsServer = await createKibanaTestServer('8.6.0', true, (req: any) =>
373373
requests.push(req)
374374
);
375-
({ port: proxyPort } = proxyServer.server.address() as AddressInfo);
375+
const server = proxyServer.server.address() as AddressInfo;
376+
proxyUrl = `http://localhost:${server.port}`;
376377
});
377378

378379
afterAll(async () => {
@@ -398,7 +399,7 @@ heartbeat.monitors:
398399
);
399400
const output = await runPush([...DEFAULT_ARGS, '--tags', 'chunk'], {
400401
CHUNK_SIZE: '1',
401-
HTTP_PROXY: `http://localhost:${proxyPort}`,
402+
HTTP_PROXY: proxyUrl,
402403
});
403404
await rm(testJourney, { force: true });
404405
expect(output).toContain('Added(2)');
@@ -421,7 +422,7 @@ heartbeat.monitors:
421422
);
422423
const output = await runPush([...DEFAULT_ARGS, '--tags', 'chunk'], {
423424
CHUNK_SIZE: '1',
424-
HTTP_PROXY: `http://localhost:${proxyPort}`,
425+
HTTP_PROXY: proxyUrl,
425426
NO_PROXY: '*',
426427
});
427428
await rm(testJourney, { force: true });
@@ -451,7 +452,7 @@ heartbeat.monitors:
451452
);
452453
const output = await runPush([...DEFAULT_ARGS, '--tags', 'chunk'], {
453454
CHUNK_SIZE: '1',
454-
HTTPS_PROXY: `http://localhost:${proxyPort}`,
455+
HTTPS_PROXY: proxyUrl,
455456
NODE_TLS_REJECT_UNAUTHORIZED: '0',
456457
});
457458
await rm(testJourney, { force: true });
@@ -465,7 +466,7 @@ heartbeat.monitors:
465466
await fakeProjectSetup(
466467
{
467468
project: { id: 'test-project', space: 'dummy', url: server.PREFIX },
468-
proxy: { uri: `http://localhost:${proxyPort}` },
469+
proxy: { uri: proxyUrl },
469470
},
470471
{ locations: ['test-loc'], schedule: 3 }
471472
);
@@ -477,13 +478,7 @@ heartbeat.monitors:
477478
journey('b', () => monitor.use({ tags: ['chunk'] }));`
478479
);
479480
const output = await runPush(
480-
[
481-
...DEFAULT_ARGS,
482-
'--tags',
483-
'chunk',
484-
'--proxy-uri',
485-
`http://localhost:${proxyPort}`,
486-
],
481+
[...DEFAULT_ARGS, '--tags', 'chunk', '--proxy-uri', proxyUrl],
487482
{
488483
CHUNK_SIZE: '1',
489484
}
@@ -499,7 +494,7 @@ heartbeat.monitors:
499494
await fakeProjectSetup(
500495
{
501496
project: { id: 'test-project', space: 'dummy', url: server.PREFIX },
502-
proxy: { uri: `http://localhost:${proxyPort}` },
497+
proxy: { uri: proxyUrl },
503498
},
504499
{ locations: ['test-loc'], schedule: 3 }
505500
);

0 commit comments

Comments
 (0)