forked from lucacasonato/deno_httpcache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin_memory_test.ts
33 lines (28 loc) · 984 Bytes
/
in_memory_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { inMemoryCache } from "./in_memory.ts";
import { assert, assertEquals } from "./test_deps.ts";
Deno.test("[in memory] cache, retrieve, delete", async () => {
const cache = inMemoryCache(5);
try {
const originalResp = new Response("Hello World", {
status: 200,
headers: {
"server": "deno",
"cache-control": "public, max-age=604800, immutable",
},
});
await cache.put("https://deno.land", originalResp);
const cachedResp = await cache.match("https://deno.land");
assert(cachedResp);
assertEquals(originalResp.status, cachedResp.status);
assertEquals(
originalResp.headers.get("server"),
cachedResp.headers.get("server"),
);
assertEquals(await originalResp.text(), await cachedResp.text());
await cache.delete("https://deno.land");
const otherCachedResp = await cache.match("https://deno.land");
assert(otherCachedResp === undefined);
} finally {
cache.close();
}
});