-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmgctl_test.ts
85 lines (78 loc) · 2.67 KB
/
mgctl_test.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
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
import { testingAsserts as ta } from "./deps-test.ts";
import { govnSvcHealth as gsh, path, shell } from "./deps.ts";
// This unit test can be run two ways:
// 1. With an auto-started child server (default)
// 2. Against an externally started server (set using GTT_TEST_BASE_URL env var)
// export GTT_TEST_BASE_URL=http://localhost:8179
// deno test -A --unstable
let baseURL = Deno.env.get("MGC_TEST_BASE_URL");
let childHttpServer: shell.RunListenableServiceResult | undefined = undefined;
let httpServerCaption = baseURL;
if (!baseURL) {
const port = 8159;
baseURL = `http://localhost:${port}`;
childHttpServer = shell.startListenableService({
port: port,
command: [
Deno.execPath(),
"run",
"-A",
"--unstable",
"mgctl.ts",
"server",
"--verbose",
],
cwd: path.dirname(path.fromFileUrl(import.meta.url)),
});
ta.assert(childHttpServer.serviceIsRunning, `Server must be started`);
const started = await childHttpServer.waitForListener(10000);
ta.assert(
started,
`Server must start listening at ${baseURL} within 10 seconds:\n ==> ${
childHttpServer.denoRunOpts.cmd.join(" ")
}`,
);
httpServerCaption = `${baseURL} PID ${childHttpServer.process.pid}`;
}
Deno.test(`mgctl.ts GET service home page (${httpServerCaption})`, async () => {
const resp = await fetch(`${baseURL}`);
ta.assertEquals(await resp.text(), "Medigy Governance Controller");
});
Deno.test(`mgctl.ts GET service health (${httpServerCaption})`, async () => {
const resp = await fetch(`${baseURL}/health`);
const health = await resp.json();
ta.assert(gsh.isHealthy(health));
// ta.assert(gsh.isServiceHealthComponents(health));
ta.assertEquals(
health.status,
"pass",
);
});
Deno.test(`mgctl.ts POST offering profile validation of Unblock Health v25.1.3 (${httpServerCaption})`, async () => {
const resp = await fetch(`${baseURL}/offering-profile/inspect/lform`, {
method: "POST",
body: JSON.stringify(
"../../../git.netspective.io/netspective-studios/git-ops-experiments/gitlab-automation-target/test-medigy-governance-offering-profile/Unblock Health Offering Profile v25_1_3.lhc-form.json",
),
});
const inspectRes = await resp.json();
ta.assertArrayIncludes(
Object.keys(inspectRes),
[
"inspectionIssues",
"isInInspectionPipe",
],
);
});
if (childHttpServer) {
Deno.test({
name: `toctl.ts stop server (${httpServerCaption})`,
fn: async () => {
await childHttpServer!.stop();
},
// because httpServer is started outside of this method, we need to let Deno know
// not to check for resource leaks
sanitizeOps: false,
sanitizeResources: false,
});
}