summaryrefslogtreecommitdiff
path: root/cli/tests/unit/kv_test.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2023-11-01 20:26:12 +0100
committerGitHub <noreply@github.com>2023-11-01 20:26:12 +0100
commitd42f1543121e7245789a96a485d1ef7645cb5fba (patch)
treed57a10ac527fe5b6796a3a8866af95f0f1a5d7bd /cli/tests/unit/kv_test.ts
parent1d19b1011bd7df50598f5981408c2d78c35b76d2 (diff)
feat: disposable Deno resources (#20845)
This commit implements Symbol.dispose and Symbol.asyncDispose for the relevant resources. Closes #20839 --------- Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tests/unit/kv_test.ts')
-rw-r--r--cli/tests/unit/kv_test.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/cli/tests/unit/kv_test.ts b/cli/tests/unit/kv_test.ts
index 4e3ce5385..0bfc75481 100644
--- a/cli/tests/unit/kv_test.ts
+++ b/cli/tests/unit/kv_test.ts
@@ -2100,3 +2100,30 @@ Deno.test({
db.close();
},
});
+
+Deno.test(
+ { permissions: { read: true } },
+ async function kvExplicitResourceManagement() {
+ let kv2: Deno.Kv;
+
+ {
+ using kv = await Deno.openKv(":memory:");
+ kv2 = kv;
+
+ const res = await kv.get(["a"]);
+ assertEquals(res.versionstamp, null);
+ }
+
+ await assertRejects(() => kv2.get(["a"]), Deno.errors.BadResource);
+ },
+);
+
+Deno.test(
+ { permissions: { read: true } },
+ async function kvExplicitResourceManagementManualClose() {
+ using kv = await Deno.openKv(":memory:");
+ kv.close();
+ await assertRejects(() => kv.get(["a"]), Deno.errors.BadResource);
+ // calling [Symbol.dispose] after manual close is a no-op
+ },
+);