From aaf56fe3fddcb36229b140b0f619a363f354105b Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Thu, 5 Oct 2023 22:56:25 +0000 Subject: [PATCH] finished tests --- filebrowser/README.md | 2 +- filebrowser/main.test.ts | 81 +++++++++++++++++++++++++++++++++++++++- filebrowser/run.sh | 4 +- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/filebrowser/README.md b/filebrowser/README.md index 694541f..134eb52 100644 --- a/filebrowser/README.md +++ b/filebrowser/README.md @@ -40,4 +40,4 @@ module "filebrowser" { agent_id = coder_agent.example.id database_path = ".config/filebrowser.db" } -``` \ No newline at end of file +``` diff --git a/filebrowser/main.test.ts b/filebrowser/main.test.ts index 9d6cd11..7541e65 100644 --- a/filebrowser/main.test.ts +++ b/filebrowser/main.test.ts @@ -6,9 +6,86 @@ import { testRequiredVariables, } from "../test"; -describe("azure-region", async () => { +describe("filebrowser", async () => { await runTerraformInit(import.meta.dir); - testRequiredVariables(import.meta.dir, {}); + testRequiredVariables(import.meta.dir, { + agent_id: "foo", + }); + it("fails with wrong database_path", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + database_path: "nofb", + }).catch((e) => { + if (!e.message.startsWith("\nError: Invalid value for variable")) { + throw e; + } + }); + }); + + it("runs with default", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + }); + const output = await executeScriptInContainer(state, "alpine"); + expect(output.exitCode).toBe(0); + expect(output.stdout).toEqual([ + "\u001b[0;1mInstalling filebrowser ", + "", + "🥳 Installation comlete! ", + "", + "👷 Starting filebrowser in background... ", + "", + "📂 Serving /root at http://localhost:13339 ", + "", + "Running 'filebrowser --noauth --root /root --port 13339' ", + "", + "📝 Logs at /tmp/filebrowser.log", + ]); + }); + + it("runs with database_path var", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + database_path: ".config/filebrowser.db", + }); + const output = await executeScriptInContainer(state, "alpine"); + expect(output.exitCode).toBe(0); + expect(output.stdout).toEqual([ + "\u001b[0;1mInstalling filebrowser ", + "", + "🥳 Installation comlete! ", + "", + "👷 Starting filebrowser in background... ", + "", + "📂 Serving /root at http://localhost:13339 ", + "", + "Running 'filebrowser --noauth --root /root --port 13339 -d .config/filebrowser.db' ", + "", + "📝 Logs at /tmp/filebrowser.log", + ]); + }); + + it("runs with folder var", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + folder: "/home/coder/project", + }); + const output = await executeScriptInContainer(state, "alpine"); + expect(output.exitCode).toBe(0); + expect(output.stdout).toEqual([ + "\u001B[0;1mInstalling filebrowser ", + "", + "🥳 Installation comlete! ", + "", + "👷 Starting filebrowser in background... ", + "", + "📂 Serving /home/coder/project at http://localhost:13339 ", + "", + "Running 'filebrowser --noauth --root /home/coder/project --port 13339' ", + "", + "📝 Logs at /tmp/filebrowser.log", + ]); + }); }); diff --git a/filebrowser/run.sh b/filebrowser/run.sh index bf60c73..ffbee0f 100644 --- a/filebrowser/run.sh +++ b/filebrowser/run.sh @@ -19,8 +19,8 @@ fi printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n" -printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n" # -d ${DB_PATH} +printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n" -filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} >${LOG_PATH} 2>&1 & # -d ${DB_PATH} +filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} >${LOG_PATH} 2>&1 & printf "📝 Logs at ${LOG_PATH} \n\n"