clone

a self-hosted sync node for lofi apps: jazz sync over iroh, ticket-gated, with no static ip or cloud needed

release/0.3.0
lofi-node / tests / storage_config_test.ts
storage_config_test.ts 2.8K
1// Storage election: user-chosen sqlite path honored on disk, unwritable paths2// fail fast and named, v1 configs migrate to v2 defaults.34import { assert, assertEquals, assertRejects } from "@std/assert";5import { createSyncNode } from "../src/node.ts";6import { initConfig, loadConfig, saveConfig } from "../src/config.ts";78Deno.test({9 name: "storage: user-chosen sqlite path is honored on disk",10 sanitizeOps: false,11 sanitizeResources: false,12 fn: async () => {13 const dir = await Deno.makeTempDir();14 const node = await createSyncNode({15 appId: crypto.randomUUID(),16 backendSecret: "b",17 adminSecret: "a",18 mesh: "off",19 storage: { type: "sqlite", path: `${dir}/my-chosen-location` },20 });21 try {22 assertEquals(node.status().jazz.storage, {23 type: "sqlite",24 path: `${dir}/my-chosen-location`,25 });26 const files = [...Deno.readDirSync(`${dir}/my-chosen-location`)].map((e) => e.name);27 assert(files.length > 0, `jazz wrote into the chosen path (found: ${files.join(", ")})`);28 } finally {29 await node.stop();30 await Deno.remove(dir, { recursive: true });31 }32 },33});3435Deno.test({36 name: "storage: unwritable path fails fast with the path named",37 sanitizeOps: false,38 sanitizeResources: false,39 fn: async () => {40 await assertRejects(41 () =>42 createSyncNode({43 appId: crypto.randomUUID(),44 backendSecret: "b",45 adminSecret: "a",46 mesh: "off",47 storage: { type: "sqlite", path: "/dev/null/not-a-dir" },48 }),49 Error,50 "/dev/null/not-a-dir",51 );52 },53});5455Deno.test("config: v1 file migrates to v2 with open access + sqlite storage", async () => {56 const dir = await Deno.makeTempDir();57 try {58 await Deno.writeTextFile(59 `${dir}/config.json`,60 JSON.stringify({61 v: 1,62 appId: "11111111-1111-1111-1111-111111111111",63 backendSecret: "b",64 adminSecret: "a",65 listenPort: 4900,66 upstream: "none",67 allowLocalFirstAuth: true,68 }),69 );70 const config = await loadConfig(dir);71 assert(config !== null);72 assertEquals(config.v, 2);73 assertEquals(config.access, "open", "v1 dirs keep today's behavior");74 assertEquals(config.storage, { type: "sqlite" });75 await saveConfig(dir, config);76 assertEquals(JSON.parse(await Deno.readTextFile(`${dir}/config.json`)).v, 2);77 } finally {78 await Deno.remove(dir, { recursive: true });79 }80});8182Deno.test("config: new inits default to ticket access", async () => {83 const dir = await Deno.makeTempDir();84 try {85 const config = await initConfig(dir);86 assertEquals(config.access, "ticket");87 assertEquals(config.storage, { type: "sqlite" });88 } finally {89 await Deno.remove(dir, { recursive: true });90 }91});