From 1317bbdf519c25cd2715180a734bb0633db1ced0 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Tue, 10 Oct 2023 16:42:39 +0000 Subject: [PATCH] added tests for vscode-web --- dotfiles/main.test.ts | 6 ++++ test.ts | 2 +- vscode-web/main.test.ts | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 vscode-web/main.test.ts diff --git a/dotfiles/main.test.ts b/dotfiles/main.test.ts index 009aaff..69eda32 100644 --- a/dotfiles/main.test.ts +++ b/dotfiles/main.test.ts @@ -12,4 +12,10 @@ describe("dotfiles", async () => { agent_id: "foo", }); + it("default output", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + }); + expect(state.outputs.dotfiles_uri.value).toBe(""); + }); }); diff --git a/test.ts b/test.ts index 6546490..a32a995 100644 --- a/test.ts +++ b/test.ts @@ -129,7 +129,7 @@ export const findResourceInstance = ( return resource.instances[0].attributes as any; }; -// assertRequiredVariables creates a test-case +// testRequiredVariables creates a test-case // for each variable provided and ensures that // the apply fails without it. export const testRequiredVariables = ( diff --git a/vscode-web/main.test.ts b/vscode-web/main.test.ts new file mode 100644 index 0000000..73c64c2 --- /dev/null +++ b/vscode-web/main.test.ts @@ -0,0 +1,67 @@ +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 var + 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!" + ]); + }); + +});