Skip to content

Commit 8fdaf2c

Browse files
committed
begin work on terraform e2e test
1 parent de3f81d commit 8fdaf2c

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,7 @@
222222
"go.testFlags": ["-short", "-coverpkg=./..."],
223223
// We often use a version of TypeScript that's ahead of the version shipped
224224
// with VS Code.
225-
"typescript.tsdk": "./site/node_modules/typescript/lib"
225+
"typescript.tsdk": "./site/node_modules/typescript/lib",
226+
// Playwright tests in VSCode will open a browser to live "view" the test.
227+
"playwright.reuseBrowser": true
226228
}

site/e2e/constants.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export const enterpriseLicense = process.env.CODER_E2E_ENTERPRISE_LICENSE ?? "";
4141

4242
// Disabling terraform tests is optional for environments without Docker + Terraform.
4343
// By default, we opt into these tests.
44-
export const requireTerraformTests = !Boolean(
45-
process.env.CODER_E2E_DISABLE_TERRAFORM,
46-
);
44+
export const requireTerraformTests = !process.env.CODER_E2E_DISABLE_TERRAFORM;
4745

4846
// Fake experiments to verify that site presents them as enabled.
4947
export const e2eFakeExperiment1 = "e2e-fake-experiment-1";

site/e2e/helpers.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
coderPort,
1919
enterpriseLicense,
2020
prometheusPort,
21-
requireEnterpriseTests, requireTerraformTests,
21+
requireEnterpriseTests,
22+
requireTerraformTests,
2223
} from "./constants";
2324
import { expectUrl } from "./expectUrl";
2425
import {
@@ -52,7 +53,6 @@ export function requiresTerraform() {
5253
test.skip(!requireTerraformTests);
5354
}
5455

55-
5656
// createWorkspace creates a workspace for a template.
5757
// It does not wait for it to be running, but it does navigate to the page.
5858
export const createWorkspace = async (
@@ -159,25 +159,48 @@ export const verifyParameters = async (
159159
}
160160
};
161161

162+
// StarterTemplates are ids of starter templates that can be used in place of
163+
// the responses payload. These starter templates will require real provisioners.
164+
export enum StarterTemplates {
165+
STARTER_DOCKER = "docker",
166+
}
167+
168+
function isStarterTemplate(
169+
input: EchoProvisionerResponses | StarterTemplates | undefined,
170+
): input is StarterTemplates {
171+
if (!input) {
172+
return false;
173+
}
174+
return typeof input === "string";
175+
}
176+
162177
// createTemplate navigates to the /templates/new page and uploads a template
163178
// with the resources provided in the responses argument.
164179
export const createTemplate = async (
165180
page: Page,
166-
responses?: EchoProvisionerResponses,
181+
responses?: EchoProvisionerResponses | StarterTemplates,
167182
): Promise<string> => {
168183
// Required to have templates submit their provisioner type as echo!
169184
await page.addInitScript({
170185
content: "window.playwright = true",
171186
});
172187

173-
await page.goto("/templates/new", { waitUntil: "domcontentloaded" });
188+
let path = "/templates/new";
189+
if (isStarterTemplate(responses)) {
190+
path += `?exampleId=${responses}`;
191+
}
192+
193+
await page.goto(path, { waitUntil: "domcontentloaded" });
174194
await expectUrl(page).toHavePathName("/templates/new");
175195

176-
await page.getByTestId("file-upload").setInputFiles({
177-
buffer: await createTemplateVersionTar(responses),
178-
mimeType: "application/x-tar",
179-
name: "template.tar",
180-
});
196+
if (!isStarterTemplate(responses)) {
197+
await page.getByTestId("file-upload").setInputFiles({
198+
buffer: await createTemplateVersionTar(responses),
199+
mimeType: "application/x-tar",
200+
name: "template.tar",
201+
});
202+
}
203+
181204
const name = randomName();
182205
await page.getByLabel("Name *").fill(name);
183206
await page.getByTestId("form-submit").click();

site/e2e/tests/createWorkspace.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { test, expect } from "@playwright/test";
22
import {
3+
StarterTemplates,
34
createTemplate,
45
createWorkspace,
56
echoResponsesWithParameters,
7+
requiresTerraform,
68
verifyParameters,
79
} from "../helpers";
810
import { beforeCoderTest } from "../hooks";
@@ -147,3 +149,18 @@ test("create workspace with disable_param search params", async ({ page }) => {
147149
await expect(page.getByLabel(/First parameter/i)).toBeDisabled();
148150
await expect(page.getByLabel(/Second parameter/i)).toBeDisabled();
149151
});
152+
153+
test("docker based workspace", async ({ page }) => {
154+
requiresTerraform();
155+
const templateName = await createTemplate(
156+
page,
157+
StarterTemplates.STARTER_DOCKER,
158+
);
159+
160+
await page.goto(`/templates/${templateName}/workspace`, {
161+
waitUntil: "domcontentloaded",
162+
});
163+
164+
await expect(page.getByLabel(/First parameter/i)).toBeDisabled();
165+
await expect(page.getByLabel(/Second parameter/i)).toBeDisabled();
166+
});

0 commit comments

Comments
 (0)