|
| 1 | +import { describe, expect, it } from "bun:test"; |
| 2 | +import { |
| 3 | + executeScriptInContainer, |
| 4 | + runTerraformApply, |
| 5 | + runTerraformInit, |
| 6 | + type scriptOutput, |
| 7 | + testRequiredVariables, |
| 8 | +} from "../test"; |
| 9 | + |
| 10 | +function testBaseLine(output: scriptOutput) { |
| 11 | + expect(output.exitCode).toBe(0); |
| 12 | + |
| 13 | + const expectedLines = [ |
| 14 | + "\u001b[[0;1mInstalling filebrowser ", |
| 15 | + "🥳 Installation complete! ", |
| 16 | + "👷 Starting filebrowser in background... ", |
| 17 | + "📂 Serving /root at http://localhost:13339 ", |
| 18 | + "📝 Logs at /tmp/filebrowser.log", |
| 19 | + ]; |
| 20 | + |
| 21 | + // we could use expect(output.stdout).toEqual(expect.arrayContaining(expectedLines)), but when it errors, it doesn't say which line is wrong |
| 22 | + for (const line of expectedLines) { |
| 23 | + expect(output.stdout).toContain(line); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +describe("filebrowser", async () => { |
| 28 | + await runTerraformInit(import.meta.dir); |
| 29 | + |
| 30 | + testRequiredVariables(import.meta.dir, { |
| 31 | + agent_id: "foo", |
| 32 | + }); |
| 33 | + |
| 34 | + it("fails with wrong database_path", async () => { |
| 35 | + const state = await runTerraformApply(import.meta.dir, { |
| 36 | + agent_id: "foo", |
| 37 | + database_path: "nofb", |
| 38 | + }).catch((e) => { |
| 39 | + if (!e.message.startsWith("\nError: Invalid value for variable")) { |
| 40 | + throw e; |
| 41 | + } |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + it("runs with default", async () => { |
| 46 | + const state = await runTerraformApply(import.meta.dir, { |
| 47 | + agent_id: "foo", |
| 48 | + }); |
| 49 | + |
| 50 | + const output = await executeScriptInContainer( |
| 51 | + state, |
| 52 | + "alpine/curl", |
| 53 | + "sh", |
| 54 | + "apk add bash", |
| 55 | + ); |
| 56 | + |
| 57 | + testBaseLine(output); |
| 58 | + }); |
| 59 | + |
| 60 | + it("runs with database_path var", async () => { |
| 61 | + const state = await runTerraformApply(import.meta.dir, { |
| 62 | + agent_id: "foo", |
| 63 | + database_path: ".config/filebrowser.db", |
| 64 | + }); |
| 65 | + |
| 66 | + const output = await await executeScriptInContainer( |
| 67 | + state, |
| 68 | + "alpine/curl", |
| 69 | + "sh", |
| 70 | + "apk add bash", |
| 71 | + ); |
| 72 | + |
| 73 | + testBaseLine(output); |
| 74 | + }); |
| 75 | + |
| 76 | + it("runs with folder var", async () => { |
| 77 | + const state = await runTerraformApply(import.meta.dir, { |
| 78 | + agent_id: "foo", |
| 79 | + folder: "/home/coder/project", |
| 80 | + }); |
| 81 | + const output = await await executeScriptInContainer( |
| 82 | + state, |
| 83 | + "alpine/curl", |
| 84 | + "sh", |
| 85 | + "apk add bash", |
| 86 | + ); |
| 87 | + }); |
| 88 | + |
| 89 | + it("runs with subdomain=false", async () => { |
| 90 | + const state = await runTerraformApply(import.meta.dir, { |
| 91 | + agent_id: "foo", |
| 92 | + agent_name: "main", |
| 93 | + subdomain: false, |
| 94 | + }); |
| 95 | + |
| 96 | + const output = await await executeScriptInContainer( |
| 97 | + state, |
| 98 | + "alpine/curl", |
| 99 | + "sh", |
| 100 | + "apk add bash", |
| 101 | + ); |
| 102 | + |
| 103 | + testBaseLine(output); |
| 104 | + }); |
| 105 | +}); |
0 commit comments