|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import path from "node:path"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | + |
| 5 | +// Secrets `checkConfig` in `index.ts` refuses to boot without. The Compose |
| 6 | +// self-host path builds `DB_CONNECTION_STRING` itself, so it is not listed. |
| 7 | +// Keep in sync when `checkConfig` gains a new required variable. |
| 8 | +const REQUIRED_SECRETS = [ |
| 9 | + "BETTER_AUTH_SECRET", |
| 10 | + "PIXEL_SIGNING_SECRET", |
| 11 | + "ESP_CREDENTIALS_ENCRYPTION_KEY", |
| 12 | + "SUPPRESSION_HASH_KEY", |
| 13 | +]; |
| 14 | + |
| 15 | +// Tests run with this package (`apps/api`) as cwd; see `test/db.ts`. |
| 16 | +const repoRoot = path.resolve(process.cwd(), "../.."); |
| 17 | +const read = (file: string) => readFileSync(path.join(repoRoot, file), "utf8"); |
| 18 | + |
| 19 | +describe("self-host configuration", () => { |
| 20 | + const envExample = read(".env.example"); |
| 21 | + const compose = read("docker-compose.yml"); |
| 22 | + |
| 23 | + it.each(REQUIRED_SECRETS)("lists %s in the root .env.example", (name) => { |
| 24 | + expect(envExample).toMatch(new RegExp(`^${name}=`, "m")); |
| 25 | + }); |
| 26 | + |
| 27 | + it.each(REQUIRED_SECRETS)( |
| 28 | + "makes docker compose fail fast without %s", |
| 29 | + (name) => { |
| 30 | + expect(compose).toContain( |
| 31 | + `${name}: \${${name}:?Set ${name} in .env}`, |
| 32 | + ); |
| 33 | + }, |
| 34 | + ); |
| 35 | +}); |
0 commit comments