From 2a40c07c3a14aaa94bd1aa5206f928e18fb09cd3 Mon Sep 17 00:00:00 2001 From: DevCats Date: Tue, 13 Jan 2026 07:53:27 -0600 Subject: [PATCH] feat(tests): add e2e test for code-server (#643) ## Description Adds e2e test for code-server that actually installs and health checks code-server ## Type of Change - [ ] New module - [ ] New template - [ ] Bug fix - [ ] Feature/enhancement - [ ] Documentation - [X] Other ## Testing & Validation - [X] Tests pass (`bun test`) - [X] Code formatted (`bun fmt`) - [X] Changes tested locally ## Related Issues --- .../coder/modules/code-server/main.test.ts | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/registry/coder/modules/code-server/main.test.ts b/registry/coder/modules/code-server/main.test.ts index 01e80883..914ae2f0 100644 --- a/registry/coder/modules/code-server/main.test.ts +++ b/registry/coder/modules/code-server/main.test.ts @@ -1,5 +1,9 @@ import { describe, expect, it } from "bun:test"; import { + execContainer, + findResourceInstance, + removeContainer, + runContainer, runTerraformApply, runTerraformInit, testRequiredVariables, @@ -34,5 +38,47 @@ describe("code-server", async () => { expect(t).toThrow("Offline mode does not allow extensions to be installed"); }); - // More tests depend on shebang refactors + it("installs and runs code-server", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + }); + + const id = await runContainer("ubuntu:latest"); + try { + await execContainer(id, [ + "bash", + "-c", + "apt-get update && apt-get install -y curl", + ]); + + const script = findResourceInstance(state, "coder_script").script; + const result = await execContainer(id, ["bash", "-c", script]); + if (result.exitCode !== 0) { + console.log(result.stdout); + console.log(result.stderr); + } + expect(result.exitCode).toBe(0); + + const version = await execContainer(id, [ + "/tmp/code-server/bin/code-server", + "--version", + ]); + expect(version.exitCode).toBe(0); + expect(version.stdout).toMatch(/\d+\.\d+\.\d+/); + + const health = await execContainer(id, [ + "curl", + "--retry", + "10", + "--retry-delay", + "1", + "--retry-all-errors", + "-sf", + "http://localhost:13337/healthz", + ]); + expect(health.exitCode).toBe(0); + } finally { + await removeContainer(id); + } + }, 60000); });