mirror of
https://github.com/lensapp/lens.git
synced 2024-09-11 09:25:26 +03: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());
|
||||
await utils.clickWelcomeButton(window);
|
||||
|
||||
frame = await utils.launchMinikubeClusterFromCatalog(window);
|
||||
frame = await utils.launchClusterFromCatalog(window);
|
||||
}, 10 * 60 * 1000);
|
||||
|
||||
afterEach(async () => {
|
||||
|
@ -3,8 +3,36 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { spawnSync } from "child_process";
|
||||
import { clusterName, kubeConfigPath } from "./utils";
|
||||
|
||||
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
|
||||
{
|
||||
const { status } = spawnSync("minikube status", { shell: true });
|
||||
|
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { createHash } from "crypto";
|
||||
import { mkdirp, remove } from "fs-extra";
|
||||
import { mkdirp, remove, writeJson } from "fs-extra";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
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() {
|
||||
const CICD = path.join(os.tmpdir(), "lens-integration-testing", uuid.v4());
|
||||
|
||||
@ -63,6 +66,17 @@ async function attemptStart() {
|
||||
await remove(CICD).catch(noop);
|
||||
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({
|
||||
args: ["--integration-testing"], // this argument turns off the blocking of quit
|
||||
executablePath: appPaths[process.platform],
|
||||
@ -109,22 +123,22 @@ export async function clickWelcomeButton(window: Page) {
|
||||
await window.click("[data-testid=welcome-menu-container] li a");
|
||||
}
|
||||
|
||||
function minikubeEntityId() {
|
||||
return createHash("md5").update(`${path.join(os.homedir(), ".kube", "config")}:minikube`).digest("hex");
|
||||
function entityId() {
|
||||
return createHash("md5").update(`${kubeConfigPath}:${clusterName}`).digest("hex");
|
||||
}
|
||||
|
||||
/**
|
||||
* From the catalog, click the minikube entity and wait for it to connect, returning its frame
|
||||
*/
|
||||
export async function launchMinikubeClusterFromCatalog(window: Page): Promise<Frame> {
|
||||
await window.click("div.TableCell >> text='minikube'");
|
||||
export async function launchClusterFromCatalog(window: Page): Promise<Frame> {
|
||||
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();
|
||||
|
||||
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]");
|
||||
|
Loading…
Reference in New Issue
Block a user