8000 Add e2e test for provisioning and claiming a prebuild · coder/coder@8a98fad · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a98fad

Browse files
committed
Add e2e test for provisioning and claiming a prebuild
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 8f051e6 commit 8a98fad

File tree

3 files changed

+83
-12
lines changed

3 files changed

+83
-12
lines changed

site/e2e/tests/presets/basic-presets-with-prebuild/main.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data "coder_workspace_preset" "goland" {
3232
"jetbrains_ide" = "GO"
3333
}
3434
prebuilds {
35-
instances = 1
35+
instances = 2
3636
}
3737
}
3838

@@ -41,9 +41,6 @@ data "coder_workspace_preset" "python" {
4141
parameters = {
4242
"jetbrains_ide" = "PY"
4343
}
44-
prebuilds {
45-
instances = 2
46-
}
4744
}
4845

4946
resource "coder_agent" "main" {
@@ -58,7 +55,9 @@ resource "coder_agent" "main" {
5855
touch ~/.init_done
5956
fi
6057
61-
# Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) here
58+
if [[ "${data.coder_workspace.me.prebuild_count}" -eq 1 ]]; then
59+
touch ~/.prebuild_note
60+
fi
6261
EOT
6362

6463
# These environment variables allow you to make Git commits right away after creating a
@@ -78,9 +77,9 @@ resource "coder_agent" "main" {
7877
# For basic resources, you can use the `coder stat` command.
7978
# If you need more control, you can write your own script.
8079
metadata {
81-
display_name = "Is Prebuild"
80+
display_name = "Was Prebuild"
8281
key = "prebuild"
83-
script = "echo ${data.coder_workspace.me.prebuild_count}"
82+
script = "[[ -e ~/.prebuild_note ]] && echo 'Yes' || echo 'No'"
8483
interval = 10
8584
timeout = 1
8685
}

site/e2e/tests/presets/prebuilds.spec.ts

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "node:path";
22
import { expect, test } from "@playwright/test";
33
import {
4+
currentUser,
45
importTemplate,
56
login,
67
randomName,
@@ -17,7 +18,7 @@ test.beforeEach(async ({ page }) => {
1718
test("create template with desired prebuilds", async ({ page, baseURL }) => {
1819
requiresLicense();
1920

20-
const expectedPrebuilds = 3;
21+
const expectedPrebuilds = 2;
2122

2223
// Create new template.
2324
const templateName = randomName();
@@ -28,15 +29,84 @@ test("create template with desired prebuilds", async ({ page, baseURL }) => {
2829

2930
await page.goto(
3031
`/workspaces?filter=owner:prebuilds%20template:${templateName}&page=1`,
32+
{ waitUntil: "domcontentloaded" },
3133
);
3234

3335
// Wait for prebuilds to show up.
3436
const prebuilds = page.getByTestId(/^workspace-.+$/);
3537
await prebuilds.first().waitFor({ state: "visible", timeout: 120_000 });
3638
expect((await prebuilds.all()).length).toEqual(expectedPrebuilds);
3739

38-
// Wait for prebuilds to become ready.
39-
const readyPrebuilds = page.getByTestId("build-status");
40-
await readyPrebuilds.first().waitFor({ state: "visible", timeout: 120_000 });
41-
expect((await readyPrebuilds.all()).length).toEqual(expectedPrebuilds);
40+
// Wait for prebuilds to start.
41+
const runningPrebuilds = page.getByTestId("build-status").getByText("Running");
42+
await runningPrebuilds.first().waitFor({ state: "visible", timeout: 120_000 });
43+
expect((await runningPrebuilds.all()).length).toEqual(expectedPrebuilds);
44+
});
45+
46+
// NOTE: requires the `workspace-prebuilds` experiment enabled!
47+
test("claim prebuild matching selected preset", async ({ page, baseURL }) => {
48+
test.setTimeout(300_000);
49+
50+
requiresLicense();
51+
52+
// Create new template.
53+
const templateName = randomName();
54+
await importTemplate(page, templateName, [
55+
path.join(__dirname, "basic-presets-with-prebuild/main.tf"),
56+
path.join(__dirname, "basic-presets-with-prebuild/.terraform.lock.hcl"),
57+
]);
58+
59+
await page.goto(
60+
`/workspaces?filter=owner:prebuilds%20template:${templateName}&page=1`,
61+
{ waitUntil: "domcontentloaded" },
62+
);
63+
64+
// Wait for prebuilds to show up.
65+
const prebuilds = page.getByTestId(/^workspace-.+$/);
66+
await prebuilds.first().waitFor({ state: "visible", timeout: 120_000 });
67+
68+
// Wait for prebuilds to start.
69+
const runningPrebuilds = page.getByTestId("build-status").getByText("Running");
70+
await runningPrebuilds.first().waitFor({ state: "visible", timeout: 120_000 });
71+
72+
// Open the first prebuild.
73+
await runningPrebuilds.first().click();
74+
await page.waitForURL(/\/@prebuilds\/prebuild-.+/);
75+
76+
// Wait for the prebuild to become ready so it's eligible to be claimed.
77+
await page.getByTestId("agent-status-ready").waitFor({ timeout: 60_000 });
78+
79+
// Create a new workspace using the same preset as one of the prebuilds.
80+
await page.goto(`/templates/coder/${templateName}/workspace`, {
81+
waitUntil: "domcontentloaded",
82+
});
83+
84+
// Visit workspace creation page for new template.
85+
await page.goto(`/templates/default/${templateName}/workspace`, {
86+
waitUntil: "domcontentloaded",
87+
});
88+
89+
// Choose a preset.
90+
await page.locator('button[aria-label="Preset"]').click();
91+
// Choose the GoLand preset.
92+
const preset = page.getByText("I Like GoLand");
93+
await expect(preset).toBeVisible();
94+
await preset.click();
95+
96+
// Create a workspace.
97+
const workspaceName = randomName();
98+
await page.locator("input[name=name]").fill(workspaceName);
99+
await page.getByRole("button", { name: "Create workspace" }).click();
100+
101+
// Wait for the workspace build display to be navigated to.
102+
const user = currentUser(page);
103+
await page.waitForURL(`/@${user.username}/${workspaceName}`, {
104+
timeout: 120_000, // Account for workspace build time.
105+
});
106+
107+
// Validate the workspace metadata that it was indeed a claimed prebuild.
108+
const indicator = page.getByText("Was Prebuild");
109+
await indicator.waitFor({ timeout: 60_000 });
110+
const text = indicator.locator("xpath=..").getByText("Yes");
111+
await text.waitFor({ timeout: 30_000 });
42112
});

site/e2e/tests/presets/presets.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ test("create template with preset and use in workspace", async ({
1212
page,
1313
baseURL,
1414
}) => {
15+
test.setTimeout(300_000);
16+
1517
// Create new template.
1618
const templateName = randomName();
1719
await importTemplate(page, templateName, [

0 commit comments

Comments
 (0)
0