-
Notifications
You must be signed in to change notification settings - Fork 11
/
greeting.spec.ts
48 lines (48 loc) · 1.59 KB
/
greeting.spec.ts
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
jest.setTimeout(120000);
describe('k8s', () => {
test('k8s', async (done) => {
expect.assertions(1);
const { execSync } = require('child_process');
execSync('/bin/bash -c "cd k8s && ./start"', { stdio: 'inherit' });
const http = require('http');
// how many times to try before failing
// the cluster require some time to get ready for action
let tries = 6;
try {
setInterval(() => {
http
.get('http://localhost:8080/?name=test', (resp: any) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk: any) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
if (data === '"hello: test"') {
expect(data).toBe('"hello: test"');
execSync('/bin/bash -c "cd k8s && ./stop"', { stdio: 'inherit' });
done();
} else {
tries--;
if (tries <= 0) {
expect(data).toBe('"hello: test"');
}
}
});
resp.on('error', (err: Error) => {
throw Error('Service responded with error: ' + err.message);
});
})
.on('error', (err: Error) => {
tries--;
if (tries <= 0) {
throw Error('http get error: ' + err.message);
}
});
}, 10000);
} catch (e) {
execSync('/bin/bash -c "cd k8s && ./stop"', { stdio: 'inherit' });
}
});
});