35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
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);
|
|
});
|
|
});
|