mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Support running smoke tests against non-minikube clusters
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
5511a2f461
commit
e24267e3d0
@ -27,7 +27,7 @@ describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => {
|
|||||||
({ window, cleanup } = await utils.start());
|
({ window, cleanup } = await utils.start());
|
||||||
await utils.clickWelcomeButton(window);
|
await utils.clickWelcomeButton(window);
|
||||||
|
|
||||||
frame = await utils.launchMinikubeClusterFromCatalog(window);
|
frame = await utils.launchClusterFromCatalog(window);
|
||||||
}, 10 * 60 * 1000);
|
}, 10 * 60 * 1000);
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|||||||
@ -3,8 +3,36 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { spawnSync } from "child_process";
|
import { spawnSync } from "child_process";
|
||||||
|
import { clusterName, kubeConfigPath } from "./utils";
|
||||||
|
|
||||||
export function minikubeReady(testNamespace: string): boolean {
|
export function minikubeReady(testNamespace: string): boolean {
|
||||||
|
if (clusterName !== "minikube") {
|
||||||
|
console.log("Not running against minikube");
|
||||||
|
|
||||||
|
{
|
||||||
|
const { status } = spawnSync(`kubectl --kubeconfig "${kubeConfigPath}" get namespace ${testNamespace}`, { shell: true });
|
||||||
|
|
||||||
|
if (status === 0) {
|
||||||
|
console.warn(`Removing existing ${testNamespace} namespace`);
|
||||||
|
|
||||||
|
const { status, stdout, stderr } = spawnSync(
|
||||||
|
`kubectl --kubeconfig "${kubeConfigPath}" delete namespace ${testNamespace}`,
|
||||||
|
{ shell: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
if (status !== 0) {
|
||||||
|
console.warn(`Error removing ${testNamespace} namespace: ${stderr.toString()}`);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(stdout.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// determine if minikube is running
|
// determine if minikube is running
|
||||||
{
|
{
|
||||||
const { status } = spawnSync("minikube status", { shell: true });
|
const { status } = spawnSync("minikube status", { shell: true });
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { createHash } from "crypto";
|
import { createHash } from "crypto";
|
||||||
import { mkdirp, remove } from "fs-extra";
|
import { mkdirp, remove, writeJson } from "fs-extra";
|
||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
@ -56,6 +56,9 @@ async function getMainWindow(app: ElectronApplication, timeout = 50_000): Promis
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const kubeConfigPath = process.env.LENS_INTEGRATION_TEST_KUBECONFIG || path.join(os.homedir(), ".kube", "config");
|
||||||
|
export const clusterName = process.env.LENS_INTEGRATION_TEST_CLUSTER_NAME || "minikube";
|
||||||
|
|
||||||
async function attemptStart() {
|
async function attemptStart() {
|
||||||
const CICD = path.join(os.tmpdir(), "lens-integration-testing", uuid.v4());
|
const CICD = path.join(os.tmpdir(), "lens-integration-testing", uuid.v4());
|
||||||
|
|
||||||
@ -63,6 +66,17 @@ async function attemptStart() {
|
|||||||
await remove(CICD).catch(noop);
|
await remove(CICD).catch(noop);
|
||||||
await mkdirp(CICD);
|
await mkdirp(CICD);
|
||||||
|
|
||||||
|
if (process.env.LENS_INTEGRATION_TEST_KUBECONFIG) {
|
||||||
|
await mkdirp(path.join(CICD, "OpenLens"));
|
||||||
|
await writeJson(path.join(CICD, "OpenLens", "lens-user-store.json"), {
|
||||||
|
preferences: {
|
||||||
|
syncKubeconfigEntries: [{
|
||||||
|
filePath: kubeConfigPath,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const app = await electron.launch({
|
const app = await electron.launch({
|
||||||
args: ["--integration-testing"], // this argument turns off the blocking of quit
|
args: ["--integration-testing"], // this argument turns off the blocking of quit
|
||||||
executablePath: appPaths[process.platform],
|
executablePath: appPaths[process.platform],
|
||||||
@ -109,22 +123,22 @@ export async function clickWelcomeButton(window: Page) {
|
|||||||
await window.click("[data-testid=welcome-menu-container] li a");
|
await window.click("[data-testid=welcome-menu-container] li a");
|
||||||
}
|
}
|
||||||
|
|
||||||
function minikubeEntityId() {
|
function entityId() {
|
||||||
return createHash("md5").update(`${path.join(os.homedir(), ".kube", "config")}:minikube`).digest("hex");
|
return createHash("md5").update(`${kubeConfigPath}:${clusterName}`).digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From the catalog, click the minikube entity and wait for it to connect, returning its frame
|
* From the catalog, click the minikube entity and wait for it to connect, returning its frame
|
||||||
*/
|
*/
|
||||||
export async function launchMinikubeClusterFromCatalog(window: Page): Promise<Frame> {
|
export async function launchClusterFromCatalog(window: Page): Promise<Frame> {
|
||||||
await window.click("div.TableCell >> text='minikube'");
|
await window.click(`div.TableCell >> text='${clusterName}'`);
|
||||||
|
|
||||||
const minikubeFrame = await window.waitForSelector(`#cluster-frame-${minikubeEntityId()}`);
|
const minikubeFrame = await window.waitForSelector(`#cluster-frame-${entityId()}`);
|
||||||
|
|
||||||
const frame = await minikubeFrame.contentFrame();
|
const frame = await minikubeFrame.contentFrame();
|
||||||
|
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
throw new Error("No iframe for minikube found");
|
throw new Error(`No iframe for "${clusterName}" found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await frame.waitForSelector("[data-testid=cluster-sidebar]");
|
await frame.waitForSelector("[data-testid=cluster-sidebar]");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user