db.test.ts 736 B

12345678910111213141516171819
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { Global } from "../../src/global"
  4. import { Installation } from "../../src/installation"
  5. import { Database } from "../../src/storage/db"
  6. describe("Database.Path", () => {
  7. test("returns database path for the current channel", () => {
  8. const db = process.env["OPENCODE_DB"]
  9. const expected = db
  10. ? path.isAbsolute(db)
  11. ? db
  12. : path.join(Global.Path.data, db)
  13. : ["latest", "beta"].includes(Installation.CHANNEL)
  14. ? path.join(Global.Path.data, "opencode.db")
  15. : path.join(Global.Path.data, `opencode-${Installation.CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
  16. expect(Database.Path).toBe(expected)
  17. })
  18. })