2021-06-21 22:05:08 +00:00
|
|
|
import { basicCheck, describe, expect, it } from "./testing.ts";
|
|
|
|
import { MemoryStorage, RefScopedStorage } from "./basic.ts";
|
2019-10-02 20:12:55 +00:00
|
|
|
|
|
|
|
describe(MemoryStorage, () => {
|
|
|
|
it("stores values in memory", async () => {
|
|
|
|
const storage = new MemoryStorage();
|
|
|
|
await basicCheck(storage);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-07 21:33:23 +00:00
|
|
|
describe(RefScopedStorage, () => {
|
2019-10-02 20:12:55 +00:00
|
|
|
it("uses a target storage, scoping its keys", async () => {
|
|
|
|
const reference1 = new MemoryStorage();
|
|
|
|
const reference2 = new MemoryStorage();
|
|
|
|
const target = new MemoryStorage();
|
|
|
|
|
2019-11-07 21:33:23 +00:00
|
|
|
let storage = new RefScopedStorage(reference1, () => target);
|
2019-10-02 20:12:55 +00:00
|
|
|
await basicCheck(storage);
|
|
|
|
|
|
|
|
await storage.set("persist", "42");
|
|
|
|
expect(await storage.get("persist")).toBe("42");
|
|
|
|
|
2019-11-07 21:33:23 +00:00
|
|
|
storage = new RefScopedStorage(() => reference1, target);
|
2019-10-02 20:12:55 +00:00
|
|
|
expect(await storage.get("persist")).toBe("42");
|
|
|
|
|
2019-11-07 21:33:23 +00:00
|
|
|
storage = new RefScopedStorage(reference2, target);
|
2019-10-02 20:12:55 +00:00
|
|
|
await storage.set("other", "thing");
|
|
|
|
expect(await storage.get("persist")).toBe(null);
|
|
|
|
expect(await storage.get("other")).toBe("thing");
|
|
|
|
|
2019-11-07 21:33:23 +00:00
|
|
|
storage = new RefScopedStorage(reference1, target);
|
2019-10-02 20:12:55 +00:00
|
|
|
expect(await storage.get("persist")).toBe("42");
|
|
|
|
expect(await storage.get("other")).toBe(null);
|
|
|
|
});
|
|
|
|
});
|