Merge pull request #84 from coder/missing-tests
This commit is contained in:
12
code-server/main.test.ts
Normal file
12
code-server/main.test.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import { runTerraformInit, testRequiredVariables } from "../test";
|
||||||
|
|
||||||
|
describe("code-server", async () => {
|
||||||
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
|
testRequiredVariables(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
|
||||||
|
// More tests depend on shebang refactors
|
||||||
|
});
|
||||||
@@ -23,7 +23,7 @@ resource "coder_script" "coder-login" {
|
|||||||
CODER_DEPLOYMENT_URL : data.coder_workspace.me.access_url
|
CODER_DEPLOYMENT_URL : data.coder_workspace.me.access_url
|
||||||
})
|
})
|
||||||
display_name = "Coder Login"
|
display_name = "Coder Login"
|
||||||
icon = "http://svgur.com/i/y5G.svg"
|
icon = "/icon/coder.svg"
|
||||||
run_on_start = true
|
run_on_start = true
|
||||||
start_blocks_login = true
|
start_blocks_login = true
|
||||||
}
|
}
|
||||||
|
|||||||
21
dotfiles/main.test.ts
Normal file
21
dotfiles/main.test.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
runTerraformApply,
|
||||||
|
runTerraformInit,
|
||||||
|
testRequiredVariables,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
|
describe("dotfiles", async () => {
|
||||||
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
|
testRequiredVariables(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
|
||||||
|
it("default output", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
expect(state.outputs.dotfiles_uri.value).toBe("");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
import { describe, expect, it } from "bun:test";
|
||||||
import {
|
import {
|
||||||
executeScriptInContainer,
|
|
||||||
runTerraformApply,
|
runTerraformApply,
|
||||||
runTerraformInit,
|
runTerraformInit,
|
||||||
testRequiredVariables,
|
testRequiredVariables,
|
||||||
@@ -22,4 +21,12 @@ describe("fly-region", async () => {
|
|||||||
});
|
});
|
||||||
expect(state.outputs.value.value).toBe("atl");
|
expect(state.outputs.value.value).toBe("atl");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("region filter", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
default: "atl",
|
||||||
|
regions: '["arn", "ams", "bos"]',
|
||||||
|
});
|
||||||
|
expect(state.outputs.value.value).toBe("");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ resource "google_compute_instance" "example" {
|
|||||||
|
|
||||||
### Add only GPU zones in the US West 1 region
|
### Add only GPU zones in the US West 1 region
|
||||||
|
|
||||||
|
Note: setting `gpu_only = true` and using a default region without GPU support, the default will be set to `null`.
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
module "gcp_region" {
|
module "gcp_region" {
|
||||||
source = "https://registry.coder.com/modules/gcp-region"
|
source = "https://registry.coder.com/modules/gcp-region"
|
||||||
|
|||||||
43
gcp-region/main.test.ts
Normal file
43
gcp-region/main.test.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
runTerraformApply,
|
||||||
|
runTerraformInit,
|
||||||
|
testRequiredVariables,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
|
describe("gcp-region", async () => {
|
||||||
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
|
testRequiredVariables(import.meta.dir, {});
|
||||||
|
|
||||||
|
it("default output", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {});
|
||||||
|
expect(state.outputs.value.value).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("customized default", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
regions: '["asia"]',
|
||||||
|
default: "asia-east1-a",
|
||||||
|
});
|
||||||
|
expect(state.outputs.value.value).toBe("asia-east1-a");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gpu only invalid default", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
regions: '["us-west2"]',
|
||||||
|
default: "us-west2-a",
|
||||||
|
gpu_only: "true",
|
||||||
|
});
|
||||||
|
expect(state.outputs.value.value).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gpu only valid default", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
regions: '["us-west2"]',
|
||||||
|
default: "us-west2-b",
|
||||||
|
gpu_only: "true",
|
||||||
|
});
|
||||||
|
expect(state.outputs.value.value).toBe("us-west2-b");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -714,7 +714,7 @@ data "coder_parameter" "region" {
|
|||||||
description = var.description
|
description = var.description
|
||||||
icon = "/icon/gcp.png"
|
icon = "/icon/gcp.png"
|
||||||
mutable = var.mutable
|
mutable = var.mutable
|
||||||
default = var.default != null && var.default != "" ? var.default : null
|
default = var.default != null && var.default != "" && (!var.gpu_only || try(local.zones[var.default].gpu, false)) ? var.default : null
|
||||||
dynamic "option" {
|
dynamic "option" {
|
||||||
for_each = {
|
for_each = {
|
||||||
for k, v in local.zones : k => v
|
for k, v in local.zones : k => v
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import { describe } from "bun:test";
|
import { it, expect, describe } from "bun:test";
|
||||||
import { runTerraformInit, testRequiredVariables } from "../test";
|
import {
|
||||||
|
runTerraformInit,
|
||||||
|
testRequiredVariables,
|
||||||
|
executeScriptInContainer,
|
||||||
|
runTerraformApply,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
describe("jetbrains-gateway`", async () => {
|
describe("jetbrains-gateway", async () => {
|
||||||
await runTerraformInit(import.meta.dir);
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
await testRequiredVariables(import.meta.dir, {
|
await testRequiredVariables(import.meta.dir, {
|
||||||
@@ -10,4 +15,16 @@ describe("jetbrains-gateway`", async () => {
|
|||||||
folder: "/baz/",
|
folder: "/baz/",
|
||||||
jetbrains_ides: '["IU", "IC", "PY"]',
|
jetbrains_ides: '["IU", "IC", "PY"]',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("default to first ide", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
agent_name: "bar",
|
||||||
|
folder: "/baz/",
|
||||||
|
jetbrains_ides: '["IU", "IC", "PY"]',
|
||||||
|
});
|
||||||
|
expect(state.outputs.jetbrains_ides.value).toBe(
|
||||||
|
'["IU","232.9921.47","https://download.jetbrains.com/idea/ideaIU-2023.2.2.tar.gz"]',
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
63
jupyterlab/main.test.ts
Normal file
63
jupyterlab/main.test.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
executeScriptInContainer,
|
||||||
|
runTerraformApply,
|
||||||
|
runTerraformInit,
|
||||||
|
testRequiredVariables,
|
||||||
|
findResourceInstance,
|
||||||
|
runContainer,
|
||||||
|
TerraformState,
|
||||||
|
execContainer,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
|
// executes the coder script after installing pip
|
||||||
|
const executeScriptInContainerWithPip = 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 respPip = await execContainer(id, [shell, "-c", "apk add py3-pip"]);
|
||||||
|
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 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 faster test to run with pip3.
|
||||||
|
// currently times out.
|
||||||
|
// it("runs with pip3", async () => {
|
||||||
|
// ...
|
||||||
|
// const output = await executeScriptInContainerWithPip(state, "alpine");
|
||||||
|
// ...
|
||||||
|
// });
|
||||||
|
});
|
||||||
33
personalize/main.test.ts
Normal file
33
personalize/main.test.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { readableStreamToText, spawn } from "bun";
|
||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
executeScriptInContainer,
|
||||||
|
runTerraformApply,
|
||||||
|
runTerraformInit,
|
||||||
|
testRequiredVariables,
|
||||||
|
runContainer,
|
||||||
|
execContainer,
|
||||||
|
findResourceInstance,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
|
describe("personalize", async () => {
|
||||||
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
|
testRequiredVariables(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
|
||||||
|
it("warns without personalize script", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
|
expect(output.exitCode).toBe(0);
|
||||||
|
expect(output.stdout).toEqual([
|
||||||
|
"✨ \u001b[0;1mYou don't have a personalize script!",
|
||||||
|
"",
|
||||||
|
"Run \u001b[36;40;1mtouch ~/personalize && chmod +x ~/personalize\u001b[0m to create one.",
|
||||||
|
"It will run every time your workspace starts. Use it to install personal packages!",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
2
test.ts
2
test.ts
@@ -129,7 +129,7 @@ export const findResourceInstance = <T extends "coder_script" | string>(
|
|||||||
return resource.instances[0].attributes as any;
|
return resource.instances[0].attributes as any;
|
||||||
};
|
};
|
||||||
|
|
||||||
// assertRequiredVariables creates a test-case
|
// testRequiredVariables creates a test-case
|
||||||
// for each variable provided and ensures that
|
// for each variable provided and ensures that
|
||||||
// the apply fails without it.
|
// the apply fails without it.
|
||||||
export const testRequiredVariables = (
|
export const testRequiredVariables = (
|
||||||
|
|||||||
24
vscode-desktop/main.test.ts
Normal file
24
vscode-desktop/main.test.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
executeScriptInContainer,
|
||||||
|
runTerraformApply,
|
||||||
|
runTerraformInit,
|
||||||
|
testRequiredVariables,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
|
describe("vscode-desktop", async () => {
|
||||||
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
|
testRequiredVariables(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
|
||||||
|
it("default output", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
expect(state.outputs.vscode_url.value).toBe(
|
||||||
|
"vscode://coder.coder-remote/open?owner=default&workspace=default&token=$SESSION_TOKEN",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -16,7 +16,7 @@ variable "agent_id" {
|
|||||||
|
|
||||||
variable "folder" {
|
variable "folder" {
|
||||||
type = string
|
type = string
|
||||||
description = "The folder to opne in VS Code."
|
description = "The folder to open in VS Code."
|
||||||
default = ""
|
default = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,3 +44,8 @@ resource "coder_app" "vscode" {
|
|||||||
"&token=$SESSION_TOKEN",
|
"&token=$SESSION_TOKEN",
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "vscode_url" {
|
||||||
|
value = coder_app.vscode.url
|
||||||
|
description = "VS Code Desktop URL."
|
||||||
|
}
|
||||||
|
|||||||
63
vscode-web/main.test.ts
Normal file
63
vscode-web/main.test.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
executeScriptInContainer,
|
||||||
|
runTerraformApply,
|
||||||
|
runTerraformInit,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
|
describe("vscode-web", async () => {
|
||||||
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
|
// replaces testRequiredVariables due to license variable
|
||||||
|
// may add a testRequiredVariablesWithLicense function later
|
||||||
|
it("missing agent_id", async () => {
|
||||||
|
try {
|
||||||
|
await runTerraformApply(import.meta.dir, {
|
||||||
|
accept_license: "true",
|
||||||
|
});
|
||||||
|
} catch (ex) {
|
||||||
|
expect(ex.message).toContain('input variable "agent_id" is not set');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("invalid license_agreement", async () => {
|
||||||
|
try {
|
||||||
|
await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
} catch (ex) {
|
||||||
|
expect(ex.message).toContain(
|
||||||
|
"You must accept the VS Code license agreement by setting accept_license=true",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails without curl", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
accept_license: "true",
|
||||||
|
});
|
||||||
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
|
expect(output.exitCode).toBe(1);
|
||||||
|
expect(output.stdout).toEqual([
|
||||||
|
"\u001b[0;1mInstalling vscode-cli!",
|
||||||
|
"Failed to install vscode-cli:", // TODO: manually test error log
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs with curl", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
accept_license: "true",
|
||||||
|
});
|
||||||
|
const output = await executeScriptInContainer(state, "alpine/curl");
|
||||||
|
expect(output.exitCode).toBe(0);
|
||||||
|
expect(output.stdout).toEqual([
|
||||||
|
"\u001b[0;1mInstalling vscode-cli!",
|
||||||
|
"🥳 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...",
|
||||||
|
"Check logs at /tmp/vscode-web.log!",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user