68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
getRequestCacheStoreResolution,
|
|
resolveRequestCacheStore,
|
|
} from "@/external/storage/cache/resolveRequestCacheStore.js";
|
|
|
|
const fakeKv = {
|
|
get: async () => null,
|
|
put: async () => undefined,
|
|
delete: async () => undefined,
|
|
};
|
|
|
|
describe("resolveRequestCacheStore", () => {
|
|
test("uses memory as the default request cache store", () => {
|
|
const store = resolveRequestCacheStore({
|
|
env: {} as Env,
|
|
});
|
|
|
|
expect(store.metadata.backend).toBe("memory");
|
|
expect(store.metadata.consistencyMode).toBe("strong");
|
|
});
|
|
|
|
test("uses KV only when the binding exists and USE_KV_CACHE is enabled", () => {
|
|
const store = resolveRequestCacheStore({
|
|
env: {
|
|
CACHE_KV: fakeKv,
|
|
USE_KV_CACHE: "true",
|
|
} as unknown as Env,
|
|
});
|
|
|
|
expect(store.metadata.backend).toBe("kv");
|
|
expect(store.metadata.consistencyMode).toBe("eventual");
|
|
});
|
|
|
|
test("uses memory when USE_KV_CACHE is enabled without a binding", () => {
|
|
const store = resolveRequestCacheStore({
|
|
env: {
|
|
USE_KV_CACHE: "true",
|
|
} as unknown as Env,
|
|
});
|
|
|
|
expect(store.metadata.backend).toBe("memory");
|
|
});
|
|
|
|
test("reports cache store resolution for ready checks", () => {
|
|
expect(
|
|
getRequestCacheStoreResolution({
|
|
CACHE_KV: fakeKv,
|
|
USE_KV_CACHE: "true",
|
|
} as unknown as Env),
|
|
).toEqual({
|
|
backend: "kv",
|
|
kvEnabled: true,
|
|
kvBound: true,
|
|
});
|
|
|
|
expect(
|
|
getRequestCacheStoreResolution({
|
|
USE_KV_CACHE: "true",
|
|
} as unknown as Env),
|
|
).toEqual({
|
|
backend: "memory",
|
|
kvEnabled: true,
|
|
kvBound: false,
|
|
});
|
|
});
|
|
});
|