-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathverify-redis-cache.spec.ts
More file actions
103 lines (88 loc) · 3.45 KB
/
Copy pathverify-redis-cache.spec.ts
File metadata and controls
103 lines (88 loc) · 3.45 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
import { ChildProcessWithoutNullStreams, exec, spawn } from "child_process";
import { expect, test } from "@support/coverage/test";
import Redis from "ioredis";
import { Common } from "../utils/common";
import { UIhelper } from "../utils/ui-helper";
function streamDataToString(data: Buffer | string): string {
return typeof data === "string" ? data : data.toString();
}
test.describe("Verify Redis Cache DB", () => {
test.beforeAll(() => {
test.info().annotations.push({
type: "component",
description: "core",
});
});
test.describe.configure({ mode: "serial" });
let common: Common;
let uiHelper: UIhelper;
let portForward: ChildProcessWithoutNullStreams;
let redis: Redis;
test.beforeEach(async ({ page }) => {
uiHelper = new UIhelper(page);
common = new Common(page);
await common.loginAsGuest();
console.log("Starting port-forward process...");
portForward = spawn("/bin/sh", [
"-c",
`
oc login --token="${process.env.K8S_CLUSTER_TOKEN}" --server="${process.env.K8S_CLUSTER_URL}" --insecure-skip-tls-verify=true &&
kubectl config set-context --current --namespace="${process.env.NAME_SPACE}" &&
kubectl port-forward service/redis 6379:6379 --namespace="${process.env.NAME_SPACE}"
`,
]);
console.log("Waiting for port-forward to be ready...");
await new Promise<void>((resolve, reject) => {
portForward.stdout.on("data", (data: Buffer | string) => {
if (streamDataToString(data).includes("Forwarding from 127.0.0.1:6379")) {
resolve();
}
});
portForward.stderr.on("data", (data: Buffer | string) => {
const message = streamDataToString(data);
console.error(`Port forwarding failed: ${message}`);
reject(new Error(`Port forwarding failed: ${message}`));
});
});
});
test("Open techdoc and verify the cache generated in redis db", async () => {
test.setTimeout(120_000);
portForward.stdout.on("data", (data: Buffer | string) => {
console.log(`Port-forward stdout: ${streamDataToString(data)}`);
});
await uiHelper.openSidebarButton("Favorites");
await uiHelper.openSidebar("Docs");
await uiHelper.clickLink("Red Hat Developer Hub");
// ensure that the docs are generated. if redis configuration has an error, this page will hang and docs won't be generated
await expect(async () => {
await uiHelper.verifyHeading("rhdh");
}).toPass({
intervals: [3_000],
timeout: 60_000,
});
console.log("Connecting to Redis...");
redis = new Redis(
`redis://${process.env.REDIS_USERNAME}:${process.env.REDIS_PASSWORD}@localhost:6379`,
);
console.log("Verifying Redis keys...");
await expect(async () => {
const keys = (await redis.keys("*")).filter((k) => k.includes("techdocs"));
expect(keys).toContainEqual(expect.stringContaining("techdocs"));
const key = keys[0];
console.log(`Verifying key format: ${key}`);
expect(key).toMatch(/(?:techdocs):(?:[A-Za-z0-9+/]+={0,2})$/gmu);
}).toPass({
intervals: [3_000],
timeout: 60_000,
});
});
test.afterEach(() => {
if (redis?.status === "ready") {
redis.disconnect();
}
console.log("Killing port-forward process with ID:", portForward.pid);
portForward.kill("SIGKILL");
console.log("Killing remaining port-forward process.");
exec(`ps aux | grep 'kubectl port-forward' | grep -v grep | awk '{print $2}' | xargs kill -9`);
});
});