-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeploy-from-github.test.ts
More file actions
85 lines (77 loc) · 2.99 KB
/
deploy-from-github.test.ts
File metadata and controls
85 lines (77 loc) · 2.99 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
/**
* Deploy an application from a GitHub repository.
*
* Verifies application is deployed correctly and is accessible via both API and static site.
*/
import { suite, test, before, after } from 'node:test';
import { deepStrictEqual, ok, strictEqual } from 'node:assert/strict';
import { startHarper, teardownHarper, type ContextWithHarper } from '@harperfast/integration-testing';
import { join } from 'node:path';
import { existsSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { parse } from 'yaml';
suite('GitHub application deployment', (ctx: ContextWithHarper) => {
before(async () => {
await startHarper(ctx);
});
after(async () => {
await teardownHarper(ctx);
});
test('verify Harper', async () => {
const response = await fetch(`${ctx.harper.operationsAPIURL}/health`);
strictEqual(response.status, 200);
const body = await response.text();
strictEqual(body, 'Harper is running.');
});
test('deploy application', async () => {
const project = 'test-application';
const githubURL = 'https://github.com/HarperFast/application-template';
const response = await fetch(ctx.harper.operationsAPIURL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
operation: 'deploy_component',
project,
package: githubURL,
restart: true,
}),
});
strictEqual(response.status, 200);
const body = await response.json();
deepStrictEqual(body, { message: 'Successfully deployed: test-application, restarting Harper' });
// Poll until the application API is ready (restart is async, fixed sleep is flaky)
const deadline = Date.now() + 30_000;
while (true) {
try {
const check = await fetch(`${ctx.harper.httpURL}/Greeting`);
if (check.status === 200) break;
} catch {
// server not yet accepting connections
}
if (Date.now() > deadline) throw new Error('Timed out waiting for application to be ready after restart');
await new Promise((resolve) => setTimeout(resolve, 250));
}
ok(existsSync(join(ctx.harper.dataRootDir, 'components', project)));
// const harperAppLock = await readFile(join(ctx.harper.dataRootDir, 'harper-application-lock.json'), 'utf-8');
// deepStrictEqual(JSON.parse(harperAppLock), {
// applications: {
// 'test-application': {}
// }
// });
const harperConfig = await readFile(join(ctx.harper.dataRootDir, 'harper-config.yaml'), 'utf-8');
const harperConfigObj = parse(harperConfig);
deepStrictEqual(harperConfigObj[project], { package: githubURL });
});
test('access application api', async () => {
const response = await fetch(`${ctx.harper.httpURL}/Greeting`);
strictEqual(response.status, 200);
const body = await response.json();
deepStrictEqual(body, { greeting: 'Hello, world!' });
});
test('access application static site', async () => {
const response = await fetch(ctx.harper.httpURL);
strictEqual(response.status, 200);
const body = await response.text();
ok(body.includes('<h1>Harper Application Template</h1>'));
});
});