/
githubmirror
/
deno
Обзор
Документация
Войти
/
githubmirror
/
deno
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/testdata/sqlite_extension_test.ts
96 строк
2 KB
David Sherret
ci: add build, test, wpt, and bench jobs (#32158)
14 фев 2026, 14:31
Не верифицирован
14 фев 2026, 14:31
c15529e
Код
Авторство
О чём код?
// Copyright 2018-2026 the Deno authors. MIT license. // NOTE: This test requires building the extension separately (it is excluded // from the workspace due to incompatible rusqlite feature requirements): // cargo build --manifest-path tests/sqlite_extension/Cargo.toml import { DatabaseSync } from "node:sqlite"; import { assertEquals, assertThrows } from "@std/assert"; import * as path from "node:path"; const extensionPath = (() => { const isWindows = Deno.build.os === "windows"; const isMac = Deno.build.os === "darwin"; const isLinux = Deno.build.os === "linux"; const currentDir = new URL(".", import.meta.url).pathname; const denoDir = path.resolve(currentDir, "../.."); let libPrefix = ""; let libSuffix = ""; if (isWindows) { libSuffix = "dll"; } else if (isMac) { libPrefix = "lib"; libSuffix = "dylib"; } else if (isLinux) { libPrefix = "lib"; libSuffix = "so"; } else { throw new Error("Unsupported platform"); } const targetDir = path.join(denoDir, "target", "debug"); return path.join(targetDir, `${libPrefix}test_sqlite_extension.${libSuffix}`); })(); const extensionExists = (() => { try { Deno.statSync(extensionPath); return true; } catch { return false; } })(); Deno.test({ name: "[node/sqlite] DatabaseSync loadExtension", ignore: !extensionExists, permissions: { read: true, write: true, ffi: true }, fn() { const db = new DatabaseSync(":memory:", { allowExtension: true, readOnly: false, }); db.loadExtension(extensionPath); const stmt = db.prepare("SELECT test_func('Hello, World!') AS result"); const { result } = stmt.get(); assertEquals(result, "Hello, World!"); db.close(); }, }); Deno.test({ name: "[node/sqlite] DatabaseSync loadExtension with FFI permission denied", permissions: { read: true, write: true, ffi: false }, fn() { assertThrows(() => { new DatabaseSync(":memory:", { allowExtension: true, readOnly: false, }); }, Deno.errors.NotCapable); }, }); Deno.test({ name: "[node/sqlite] DatabaseSync loadExtension with invalid path", permissions: { read: true, write: true, ffi: true }, fn() { const db = new DatabaseSync(":memory:", { allowExtension: true, readOnly: false, }); // Loading a non-existent extension should throw assertThrows(() => { db.loadExtension("/path/to/nonexistent/extension"); }, Error); db.close(); }, });