Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit c7c9fa9

Browse files
authored
Merge pull request #84 from coder/missing-tests
2 parents 5173854 + c23edf4 commit c7c9fa9

File tree

14 files changed

+298
-8
lines changed

14 files changed

+298
-8
lines changed

code-server/main.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from "bun:test";
2+
import { runTerraformInit, testRequiredVariables } from "../test";
3+
4+
describe("code-server", async () => {
5+
await runTerraformInit(import.meta.dir);
6+
7+
testRequiredVariables(import.meta.dir, {
8+
agent_id: "foo",
9+
});
10+
11+
// More tests depend on shebang refactors
12+
});

coder-login/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "coder_script" "coder-login" {
2323
CODER_DEPLOYMENT_URL : data.coder_workspace.me.access_url
2424
})
2525
display_name = "Coder Login"
26-
icon = "http://svgur.com/i/y5G.svg"
26+
icon = "/icon/coder.svg"
2727
run_on_start = true
2828
start_blocks_login = true
2929
}

dotfiles/main.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
runTerraformApply,
4+
runTerraformInit,
5+
testRequiredVariables,
6+
} from "../test";
7+
8+
describe("dotfiles", async () => {
9+
await runTerraformInit(import.meta.dir);
10+
11+
testRequiredVariables(import.meta.dir, {
12+
agent_id: "foo",
13+
});
14+
15+
it("default output", async () => {
16+
const state = await runTerraformApply(import.meta.dir, {
17+
agent_id: "foo",
18+
});
19+
expect(state.outputs.dotfiles_uri.value).toBe("");
20+
});
21+
});

fly-region/main.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it } from "bun:test";
22
import {
3-
executeScriptInContainer,
43
runTerraformApply,
54
runTerraformInit,
65
testRequiredVariables,
@@ -22,4 +21,12 @@ describe("fly-region", async () => {
2221
});
2322
expect(state.outputs.value.value).toBe("atl");
2423
});
24+
25+
it("region filter", async () => {
26+
const state = await runTerraformApply(import.meta.dir, {
27+
default: "atl",
28+
regions: '["arn", "ams", "bos"]',
29+
});
30+
expect(state.outputs.value.value).toBe("");
31+
});
2532
});

gcp-region/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ resource "google_compute_instance" "example" {
2828

2929
### Add only GPU zones in the US West 1 region
3030

31+
Note: setting `gpu_only = true` and using a default region without GPU support, the default will be set to `null`.
32+
3133
```hcl
3234
module "gcp_region" {
3335
source = "https://registry.coder.com/modules/gcp-region"

gcp-region/main.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
runTerraformApply,
4+
runTerraformInit,
5+
testRequiredVariables,
6+
} from "../test";
7+
8+
describe("gcp-region", async () => {
9+
await runTerraformInit(import.meta.dir);
10+
11+
testRequiredVariables(import.meta.dir, {});
12+
13+
it("default output", async () => {
14+
const state = await runTerraformApply(import.meta.dir, {});
15+
expect(state.outputs.value.value).toBe("");
16+
});
17+
18+
it("customized default", async () => {
19+
const state = await runTerraformApply(import.meta.dir, {
20+
regions: '["asia"]',
21+
default: "asia-east1-a",
22+
});
23+
expect(state.outputs.value.value).toBe("asia-east1-a");
24+
});
25+
26+
it("gpu only invalid default", async () => {
27+
const state = await runTerraformApply(import.meta.dir, {
28+
regions: '["us-west2"]',
29+
default: "us-west2-a",
30+
gpu_only: "true",
31+
});
32+
expect(state.outputs.value.value).toBe("");
33+
});
34+
35+
it("gpu only valid default", async () => {
36+
const state = await runTerraformApply(import.meta.dir, {
37+
regions: '["us-west2"]',
38+
default: "us-west2-b",
39+
gpu_only: "true",
40+
});
41+
expect(state.outputs.value.value).toBe("us-west2-b");
42+
});
43+
});

gcp-region/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ data "coder_parameter" "region" {
714714
description = var.description
715715
icon = "/icon/gcp.png"
716716
mutable = var.mutable
717-
default = var.default != null && var.default != "" ? var.default : null
717+
default = var.default != null && var.default != "" && (!var.gpu_only || try(local.zones[var.default].gpu, false)) ? var.default : null
718718
dynamic "option" {
719719
for_each = {
720720
for k, v in local.zones : k => v

jetbrains-gateway/main.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { describe } from "bun:test";
2-
import { runTerraformInit, testRequiredVariables } from "../test";
1+
import { it, expect, describe } from "bun:test";
2+
import {
3+
runTerraformInit,
4+
testRequiredVariables,
5+
executeScriptInContainer,
6+
runTerraformApply,
7+
} from "../test";
38

4-
describe("jetbrains-gateway`", async () => {
9+
describe("jetbrains-gateway", async () => {
510
await runTerraformInit(import.meta.dir);
611

712
await testRequiredVariables(import.meta.dir, {
@@ -10,4 +15,16 @@ describe("jetbrains-gateway`", async () => {
1015
folder: "/baz/",
1116
jetbrains_ides: '["IU", "IC", "PY"]',
1217
});
18+
19+
it("default to first ide", async () => {
20+
const state = await runTerraformApply(import.meta.dir, {
21+
agent_id: "foo",
22+
agent_name: "bar",
23+
folder: "/baz/",
24+
jetbrains_ides: '["IU", "IC", "PY"]',
25+
});
26+
expect(state.outputs.jetbrains_ides.value).toBe(
27+
'["IU","232.9921.47","https://download.jetbrains.com/idea/ideaIU-2023.2.2.tar.gz"]',
28+
);
29+
});
1330
});

jupyterlab/main.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
executeScriptInContainer,
4+
runTerraformApply,
5+
runTerraformInit,
6+
testRequiredVariables,
7+
findResourceInstance,
8+
runContainer,
9+
TerraformState,
10+
execContainer,
11+
} from "../test";
12+
13+
// executes the coder script after installing pip
14+
const executeScriptInContainerWithPip = async (
15+
state: TerraformState,
16+
image: string,
17+
shell: string = "sh",
18+
): Promise<{
19+
exitCode: number;
20+
stdout: string[];
21+
stderr: string[];
22+
}> => {
23+
const instance = findResourceInstance(state, "coder_script");
24+
const id = await runContainer(image);
25+
const respPip = await execContainer(id, [shell, "-c", "apk add py3-pip"]);
26+
const resp = await execContainer(id, [shell, "-c", instance.script]);
27+
const stdout = resp.stdout.trim().split("\n");
28+
const stderr = resp.stderr.trim().split("\n");
29+
return {
30+
exitCode: resp.exitCode,
31+
stdout,
32+
stderr,
33+
};
34+
};
35+
36+
describe("jupyterlab", async () => {
37+
await runTerraformInit(import.meta.dir);
38+
39+
testRequiredVariables(import.meta.dir, {
40+
agent_id: "foo",
41+
});
42+
43+
it("fails without pip3", async () => {
44+
const state = await runTerraformApply(import.meta.dir, {
45+
agent_id: "foo",
46+
});
47+
const output = await executeScriptInContainer(state, "alpine");
48+
expect(output.exitCode).toBe(1);
49+
expect(output.stdout).toEqual([
50+
"\u001B[0;1mInstalling jupyterlab!",
51+
"pip3 is not installed",
52+
"Please install pip3 in your Dockerfile/VM image before running this script",
53+
]);
54+
});
55+
56+
// TODO: Add faster test to run with pip3.
57+
// currently times out.
58+
// it("runs with pip3", async () => {
59+
// ...
60+
// const output = await executeScriptInContainerWithPip(state, "alpine");
61+
// ...
62+
// });
63+
});

personalize/main.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { readableStreamToText, spawn } from "bun";
2+
import { describe, expect, it } from "bun:test";
3+
import {
4+
executeScriptInContainer,
5+
runTerraformApply,
6+
runTerraformInit,
7+
testRequiredVariables,
8+
runContainer,
9+
execContainer,
10+
findResourceInstance,
11+
} from "../test";
12+
13+
describe("personalize", async () => {
14+
await runTerraformInit(import.meta.dir);
15+
16+
testRequiredVariables(import.meta.dir, {
17+
agent_id: "foo",
18+
});
19+
20+
it("warns without personalize script", async () => {
21+
const state = await runTerraformApply(import.meta.dir, {
22+
agent_id: "foo",
23+
});
24+
const output = await executeScriptInContainer(state, "alpine");
25+
expect(output.exitCode).toBe(0);
26+
expect(output.stdout).toEqual([
27+
"✨ \u001b[0;1mYou don't have a personalize script!",
28+
"",
29+
"Run \u001b[36;40;1mtouch ~/personalize && chmod +x ~/personalize\u001b[0m to create one.",
30+
"It will run every time your workspace starts. Use it to install personal packages!",
31+
]);
32+
});
33+
});

0 commit comments

Comments
 (0)