mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-17 10:06:00 +00:00
test: establish storage adapter contracts
This commit is contained in:
@@ -2,9 +2,10 @@ import * as fs from "node:fs/promises";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { storageAdapterContractCases } from "@/apps/storageAdapterContract";
|
||||
import { NodeStorageAdapter } from "./NodeStorageAdapter";
|
||||
|
||||
describe("NodeStorageAdapter binary I/O", () => {
|
||||
describe("NodeStorageAdapter", () => {
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
async function createAdapter() {
|
||||
@@ -17,6 +18,12 @@ describe("NodeStorageAdapter binary I/O", () => {
|
||||
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
|
||||
for (const contractCase of storageAdapterContractCases) {
|
||||
it(contractCase.name, async () => {
|
||||
await contractCase.run(await createAdapter());
|
||||
});
|
||||
}
|
||||
|
||||
it("writes and reads binary data without corruption", async () => {
|
||||
const adapter = await createAdapter();
|
||||
const expected = Uint8Array.from([0x00, 0x7f, 0x80, 0xff, 0x42]);
|
||||
@@ -37,4 +44,7 @@ describe("NodeStorageAdapter binary I/O", () => {
|
||||
expect(result.byteLength).toBe(expected.byteLength);
|
||||
expect(Array.from(new Uint8Array(result))).toEqual([0x10, 0x20, 0x30]);
|
||||
});
|
||||
|
||||
it.todo("rejects paths that escape the configured root");
|
||||
it.todo("rejects removing the configured root through an empty path");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user