summaryrefslogtreecommitdiff
path: root/tests/unit/os_test.ts
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-08-19 16:21:27 -0400
committerGitHub <noreply@github.com>2024-08-19 16:21:27 -0400
commitbf510544ef26b89d4c2ae935893eaf62995ed903 (patch)
treeb4cbe166e239f5e95f9a17f9d93f025f394e85a7 /tests/unit/os_test.ts
parentee2b6899a1e6a3108bad43443f130ca2dd86a697 (diff)
chore: improve accessing special file test (#25099)
Diffstat (limited to 'tests/unit/os_test.ts')
-rw-r--r--tests/unit/os_test.ts44
1 files changed, 14 insertions, 30 deletions
diff --git a/tests/unit/os_test.ts b/tests/unit/os_test.ts
index 80b421e63..42b598511 100644
--- a/tests/unit/os_test.ts
+++ b/tests/unit/os_test.ts
@@ -3,7 +3,6 @@ import {
assert,
assertEquals,
assertNotEquals,
- assertStringIncludes,
assertThrows,
} from "./test_util.ts";
@@ -197,36 +196,21 @@ Deno.test({ permissions: { read: false } }, function execPathPerm() {
);
});
-Deno.test(async function execPathPerm() {
- if (Deno.build.os !== "linux") return;
- // This is hack to bypass a bug in deno test runner,
- // Currently if you specify {read: true} permission, it will stil pass --allow-all (tests are run with deno test --allow-all) implicitly, so this test won't work
- // The workaround is to spawn a deno executable with the needed permissions
- // TODO(#25085): remove this hack when the bug is fixed
- const cmd = new Deno.Command(Deno.execPath(), {
- args: ["run", "--allow-read", "-"],
- stdin: "piped",
- stderr: "piped",
- }).spawn();
- const stdinWriter = cmd.stdin.getWriter();
- await stdinWriter
- .write(
- new TextEncoder().encode('Deno.readTextFileSync("/proc/net/dev")'),
+Deno.test(
+ {
+ ignore: Deno.build.os !== "linux",
+ permissions: { read: true, run: false },
+ },
+ function procRequiresAllowAll() {
+ assertThrows(
+ () => {
+ Deno.readTextFileSync("/proc/net/dev");
+ },
+ Deno.errors.PermissionDenied,
+ `Requires all access to "/proc/net/dev", run again with the --allow-all flag`,
);
- await stdinWriter.close();
- await cmd.status;
-
- const stderrReder = cmd.stderr.getReader();
- const error = await stderrReder
- .read()
- .then((r) => new TextDecoder().decode(r.value));
- await stderrReder.cancel();
-
- assertStringIncludes(
- error,
- `PermissionDenied: Requires all access to "/proc/net/dev", run again with the --allow-all flag`,
- );
-});
+ },
+);
Deno.test(
{ permissions: { sys: ["loadavg"] } },