1
0
silverbullet/cli/syscalls/index.test.ts

39 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-08-04 19:17:36 +00:00
import { DenoKVStore } from "../../plugos/lib/kv_store.deno_kv.ts";
2023-08-04 16:56:55 +00:00
import { assertEquals } from "../../test_deps.ts";
import { pageIndexSyscalls } from "./index.ts";
Deno.test("Test KV index", async () => {
const ctx: any = {};
2023-08-04 19:17:36 +00:00
const kv = new DenoKVStore();
await kv.init("test.db");
const calls = pageIndexSyscalls(kv);
2023-08-04 16:56:55 +00:00
await calls["index.set"](ctx, "page", "test", "value");
assertEquals(await calls["index.get"](ctx, "page", "test"), "value");
await calls["index.delete"](ctx, "page", "test");
assertEquals(await calls["index.get"](ctx, "page", "test"), null);
await calls["index.batchSet"](ctx, "page", [{
key: "attr:test",
value: "value",
}, {
key: "attr:test2",
value: "value2",
}, { key: "random", value: "value3" }]);
await calls["index.batchSet"](ctx, "page2", [{
key: "attr:test",
value: "value",
}, {
key: "attr:test2",
value: "value2",
}, { key: "random", value: "value3" }]);
let results = await calls["index.queryPrefix"](ctx, "attr:");
assertEquals(results.length, 4);
2023-08-04 19:17:36 +00:00
console.log("here");
2023-08-04 16:56:55 +00:00
await calls["index.clearPageIndexForPage"](ctx, "page");
results = await calls["index.queryPrefix"](ctx, "attr:");
assertEquals(results.length, 2);
await calls["index.clearPageIndex"](ctx);
results = await calls["index.queryPrefix"](ctx, "");
assertEquals(results.length, 0);
2023-08-04 19:17:36 +00:00
await kv.delete();
2023-08-04 16:56:55 +00:00
});