-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.mjs
46 lines (31 loc) · 948 Bytes
/
test.mjs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import dotenv from "dotenv-safe";
import crypto from "crypto";
import test from "ava";
import CloudflareKV from "./index.mjs";
dotenv.config();
const options = {
accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
apiToken: process.env.CLOUDFLARE_API_TOKEN,
namespaceId: process.env.CLOUDFLARE_NAMESPACE_ID,
};
const key = crypto.randomBytes(32).toString("hex");
async function wait(t) {
await new Promise((resolve) => setTimeout(resolve, 5000));
t.is(true, true);
}
test("put", async (t) => {
const kv = new CloudflareKV(options);
const result = await kv.put(key, { got: "ava" });
t.is(result, undefined);
});
test("wait (put)", wait);
test("get", async (t) => {
const kv = new CloudflareKV(options);
const result = await kv.get(key);
t.deepEqual(result, { got: "ava" });
});
test("delete", async (t) => {
const kv = new CloudflareKV(options);
const result = await kv.delete(key);
t.is(result, undefined);
});