added small test for jupyterlab

pull/84/head
Stephen Kirby 2 years ago
parent 698d8168f2
commit a83cd5b140

@ -25,7 +25,7 @@ describe("fly-region", async () => {
it("region filter", async () => { it("region filter", async () => {
const state = await runTerraformApply(import.meta.dir, { const state = await runTerraformApply(import.meta.dir, {
default: "atl", default: "atl",
regions: '["arn", "ams", "bos"]' regions: '["arn", "ams", "bos"]',
}); });
expect(state.outputs.value.value).toBe(""); expect(state.outputs.value.value).toBe("");
}); });

@ -0,0 +1,57 @@
import { describe, expect, it } from "bun:test";
import {
executeScriptInContainer,
runTerraformApply,
runTerraformInit,
testRequiredVariables,
findResourceInstance,
runContainer,
} from "../test";
const executeScriptInContainer = async (
state: TerraformState,
image: string,
shell: string = "sh",
): Promise<{
exitCode: number;
stdout: string[];
stderr: string[];
}> => {
const instance = findResourceInstance(state, "coder_script");
const id = await runContainer(image);
const resp = await execContainer(id, [shell, "-c", instance.script]);
const stdout = resp.stdout.trim().split("\n");
const stderr = resp.stderr.trim().split("\n");
return {
exitCode: resp.exitCode,
stdout,
stderr,
};
};
describe("jupyterlab", async () => {
await runTerraformInit(import.meta.dir);
testRequiredVariables(import.meta.dir, {
agent_id: "foo",
});
it("fails without pip3", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
});
const instance = findResourceInstance(state, "coder_script");
const id = await runContainer("alpine");
const output = await executeScriptInContainer(state, "alpine");
expect(output.exitCode).toBe(1);
expect(output.stdout).toEqual([
"\u001B[0;1mInstalling jupyterlab!",
"pip3 is not installed",
"Please install pip3 in your Dockerfile/VM image before running this script",
]);
});
// TODO: Add test that runs with pip
// May be best to use dockerfile
});

@ -13,15 +13,12 @@ describe("vscode-desktop", async () => {
agent_id: "foo", agent_id: "foo",
}); });
it("default output", async () => { it("default output", async () => {
const state = await runTerraformApply(import.meta.dir, { const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo", agent_id: "foo",
}); });
expect(state.outputs.vscode_url.value).toBe( expect(state.outputs.vscode_url.value).toBe(
"vscode://coder.coder-remote/open?owner=default&workspace=default&token=$SESSION_TOKEN" "vscode://coder.coder-remote/open?owner=default&workspace=default&token=$SESSION_TOKEN",
); );
}); });
}); });

@ -46,6 +46,6 @@ resource "coder_app" "vscode" {
} }
output "vscode_url" { output "vscode_url" {
value = coder_app.vscode.url value = coder_app.vscode.url
description = "VS Code Desktop URL." description = "VS Code Desktop URL."
} }

@ -8,7 +8,6 @@ import {
describe("vscode-web", async () => { describe("vscode-web", async () => {
await runTerraformInit(import.meta.dir); await runTerraformInit(import.meta.dir);
// replaces testRequiredVariables due to license variable // replaces testRequiredVariables due to license variable
// may add a testRequiredVariablesWithLicense function later // may add a testRequiredVariablesWithLicense function later
it("missing agent_id", async () => { it("missing agent_id", async () => {
@ -17,21 +16,18 @@ describe("vscode-web", async () => {
accept_license: "true", accept_license: "true",
}); });
} catch (ex) { } catch (ex) {
expect(ex.message).toContain( expect(ex.message).toContain('input variable "agent_id" is not set');
'input variable "agent_id" is not set'
);
} }
}); });
it("invalid license_agreement", async () => { it("invalid license_agreement", async () => {
try { try {
await runTerraformApply(import.meta.dir, { await runTerraformApply(import.meta.dir, {
agent_id: "foo", agent_id: "foo",
}); });
} catch (ex) { } catch (ex) {
expect(ex.message).toContain( expect(ex.message).toContain(
'You must accept the VS Code license agreement by setting accept_license=true' "You must accept the VS Code license agreement by setting accept_license=true",
); );
} }
}); });
@ -61,8 +57,7 @@ describe("vscode-web", async () => {
"🥳 vscode-cli has been installed.", "🥳 vscode-cli has been installed.",
"", "",
"👷 Running /tmp/vscode-cli/bin/code serve-web --port 13338 --without-connection-token --accept-server-license-terms in the background...", "👷 Running /tmp/vscode-cli/bin/code serve-web --port 13338 --without-connection-token --accept-server-license-terms in the background...",
"Check logs at /tmp/vscode-web.log!" "Check logs at /tmp/vscode-web.log!",
]); ]);
}); });
}); });

Loading…
Cancel
Save