Key/value storage, local or remote
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
storage/src/basic.test.ts

35 lines
1.2 KiB

import { basicCheck, describe, expect, it } from "./testing.ts";
import { MemoryStorage, RefScopedStorage } from "./basic.ts";
describe(MemoryStorage, () => {
it("stores values in memory", async () => {
const storage = new MemoryStorage();
await basicCheck(storage);
});
});
describe(RefScopedStorage, () => {
it("uses a target storage, scoping its keys", async () => {
const reference1 = new MemoryStorage();
const reference2 = new MemoryStorage();
const target = new MemoryStorage();
let storage = new RefScopedStorage(reference1, () => target);
await basicCheck(storage);
await storage.set("persist", "42");
expect(await storage.get("persist")).toBe("42");
storage = new RefScopedStorage(() => reference1, target);
expect(await storage.get("persist")).toBe("42");
storage = new RefScopedStorage(reference2, target);
await storage.set("other", "thing");
expect(await storage.get("persist")).toBe(null);
expect(await storage.get("other")).toBe("thing");
storage = new RefScopedStorage(reference1, target);
expect(await storage.get("persist")).toBe("42");
expect(await storage.get("other")).toBe(null);
});
});