summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/network_interfaces_test.ts5
-rw-r--r--cli/tests/unit/os_test.ts62
-rw-r--r--cli/tests/unit/permissions_test.ts17
3 files changed, 58 insertions, 26 deletions
diff --git a/cli/tests/unit/network_interfaces_test.ts b/cli/tests/unit/network_interfaces_test.ts
index 120f58763..a0e6e691a 100644
--- a/cli/tests/unit/network_interfaces_test.ts
+++ b/cli/tests/unit/network_interfaces_test.ts
@@ -1,7 +1,10 @@
import { assert } from "./test_util.ts";
Deno.test(
- { name: "Deno.networkInterfaces", permissions: { env: true } },
+ {
+ name: "Deno.networkInterfaces",
+ permissions: { sys: ["networkInterfaces"] },
+ },
() => {
const networkInterfaces = Deno.networkInterfaces();
assert(Array.isArray(networkInterfaces));
diff --git a/cli/tests/unit/os_test.ts b/cli/tests/unit/os_test.ts
index bdbf7f0ca..d620ae4e3 100644
--- a/cli/tests/unit/os_test.ts
+++ b/cli/tests/unit/os_test.ts
@@ -187,49 +187,61 @@ Deno.test({ permissions: { read: false } }, function execPathPerm() {
);
});
-Deno.test({ permissions: { env: true } }, function loadavgSuccess() {
- const load = Deno.loadavg();
- assertEquals(load.length, 3);
-});
+Deno.test(
+ { permissions: { sys: ["loadavg"] } },
+ function loadavgSuccess() {
+ const load = Deno.loadavg();
+ assertEquals(load.length, 3);
+ },
+);
-Deno.test({ permissions: { env: false } }, function loadavgPerm() {
+Deno.test({ permissions: { sys: false } }, function loadavgPerm() {
assertThrows(() => {
Deno.loadavg();
}, Deno.errors.PermissionDenied);
});
-Deno.test({ permissions: { env: true } }, function hostnameDir() {
- assertNotEquals(Deno.hostname(), "");
-});
+Deno.test(
+ { permissions: { sys: ["hostname"] } },
+ function hostnameDir() {
+ assertNotEquals(Deno.hostname(), "");
+ },
+);
-Deno.test({ permissions: { env: false } }, function hostnamePerm() {
+Deno.test({ permissions: { sys: false } }, function hostnamePerm() {
assertThrows(() => {
Deno.hostname();
}, Deno.errors.PermissionDenied);
});
-Deno.test({ permissions: { env: true } }, function releaseDir() {
- assertNotEquals(Deno.osRelease(), "");
-});
+Deno.test(
+ { permissions: { sys: ["osRelease"] } },
+ function releaseDir() {
+ assertNotEquals(Deno.osRelease(), "");
+ },
+);
-Deno.test({ permissions: { env: false } }, function releasePerm() {
+Deno.test({ permissions: { sys: false } }, function releasePerm() {
assertThrows(() => {
Deno.osRelease();
}, Deno.errors.PermissionDenied);
});
-Deno.test({ permissions: { env: true } }, function systemMemoryInfo() {
- const info = Deno.systemMemoryInfo();
- assert(info.total >= 0);
- assert(info.free >= 0);
- assert(info.available >= 0);
- assert(info.buffers >= 0);
- assert(info.cached >= 0);
- assert(info.swapTotal >= 0);
- assert(info.swapFree >= 0);
-});
+Deno.test(
+ { permissions: { sys: ["systemMemoryInfo"] } },
+ function systemMemoryInfo() {
+ const info = Deno.systemMemoryInfo();
+ assert(info.total >= 0);
+ assert(info.free >= 0);
+ assert(info.available >= 0);
+ assert(info.buffers >= 0);
+ assert(info.cached >= 0);
+ assert(info.swapTotal >= 0);
+ assert(info.swapFree >= 0);
+ },
+);
-Deno.test({ permissions: { env: true } }, function getUid() {
+Deno.test({ permissions: { sys: ["getUid"] } }, function getUid() {
if (Deno.build.os === "windows") {
assertEquals(Deno.getUid(), null);
} else {
@@ -239,7 +251,7 @@ Deno.test({ permissions: { env: true } }, function getUid() {
}
});
-Deno.test({ permissions: { env: true } }, function getGid() {
+Deno.test({ permissions: { sys: ["getGid"] } }, function getGid() {
if (Deno.build.os === "windows") {
assertEquals(Deno.getGid(), null);
} else {
diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts
index 551e9bdcd..c0945bb59 100644
--- a/cli/tests/unit/permissions_test.ts
+++ b/cli/tests/unit/permissions_test.ts
@@ -19,6 +19,23 @@ Deno.test(async function permissionNetInvalidHost() {
}, URIError);
});
+Deno.test(async function permissionSysValidKind() {
+ await Deno.permissions.query({ name: "sys", kind: "loadavg" });
+ await Deno.permissions.query({ name: "sys", kind: "osRelease" });
+ await Deno.permissions.query({ name: "sys", kind: "networkInterfaces" });
+ await Deno.permissions.query({ name: "sys", kind: "systemMemoryInfo" });
+ await Deno.permissions.query({ name: "sys", kind: "hostname" });
+ await Deno.permissions.query({ name: "sys", kind: "getUid" });
+ await Deno.permissions.query({ name: "sys", kind: "getGid" });
+});
+
+Deno.test(async function permissionSysInvalidKind() {
+ await assertRejects(async () => {
+ // deno-lint-ignore no-explicit-any
+ await Deno.permissions.query({ name: "sys", kind: "abc" as any });
+ }, TypeError);
+});
+
Deno.test(async function permissionQueryReturnsEventTarget() {
const status = await Deno.permissions.query({ name: "hrtime" });
assert(["granted", "denied", "prompt"].includes(status.state));