mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
test(cli): align unit test permissions with runtime test permissions (#12189)
This commit is contained in:
parent
87e78802b0
commit
830586d242
45 changed files with 664 additions and 574 deletions
|
@ -8,7 +8,7 @@ import {
|
|||
unitTest,
|
||||
} from "./test_util.ts";
|
||||
|
||||
unitTest({ perms: { read: true } }, function readFileSyncSuccess() {
|
||||
unitTest({ permissions: { read: true } }, function readFileSyncSuccess() {
|
||||
const data = Deno.readFileSync("cli/tests/testdata/fixture.json");
|
||||
assert(data.byteLength > 0);
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
|
@ -17,7 +17,7 @@ unitTest({ perms: { read: true } }, function readFileSyncSuccess() {
|
|||
assertEquals(pkg.name, "deno");
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, function readFileSyncUrl() {
|
||||
unitTest({ permissions: { read: true } }, function readFileSyncUrl() {
|
||||
const data = Deno.readFileSync(
|
||||
pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"),
|
||||
);
|
||||
|
@ -28,19 +28,19 @@ unitTest({ perms: { read: true } }, function readFileSyncUrl() {
|
|||
assertEquals(pkg.name, "deno");
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: false } }, function readFileSyncPerm() {
|
||||
unitTest({ permissions: { read: false } }, function readFileSyncPerm() {
|
||||
assertThrows(() => {
|
||||
Deno.readFileSync("cli/tests/testdata/fixture.json");
|
||||
}, Deno.errors.PermissionDenied);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, function readFileSyncNotFound() {
|
||||
unitTest({ permissions: { read: true } }, function readFileSyncNotFound() {
|
||||
assertThrows(() => {
|
||||
Deno.readFileSync("bad_filename");
|
||||
}, Deno.errors.NotFound);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, async function readFileUrl() {
|
||||
unitTest({ permissions: { read: true } }, async function readFileUrl() {
|
||||
const data = await Deno.readFile(
|
||||
pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"),
|
||||
);
|
||||
|
@ -51,7 +51,7 @@ unitTest({ perms: { read: true } }, async function readFileUrl() {
|
|||
assertEquals(pkg.name, "deno");
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, async function readFileSuccess() {
|
||||
unitTest({ permissions: { read: true } }, async function readFileSuccess() {
|
||||
const data = await Deno.readFile("cli/tests/testdata/fixture.json");
|
||||
assert(data.byteLength > 0);
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
|
@ -60,20 +60,20 @@ unitTest({ perms: { read: true } }, async function readFileSuccess() {
|
|||
assertEquals(pkg.name, "deno");
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: false } }, async function readFilePerm() {
|
||||
unitTest({ permissions: { read: false } }, async function readFilePerm() {
|
||||
await assertRejects(async () => {
|
||||
await Deno.readFile("cli/tests/testdata/fixture.json");
|
||||
}, Deno.errors.PermissionDenied);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, function readFileSyncLoop() {
|
||||
unitTest({ permissions: { read: true } }, function readFileSyncLoop() {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
Deno.readFileSync("cli/tests/testdata/fixture.json");
|
||||
}
|
||||
});
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true } },
|
||||
{ permissions: { read: true } },
|
||||
async function readFileDoesNotLeakResources() {
|
||||
const resourcesBefore = Deno.resources();
|
||||
await assertRejects(async () => await Deno.readFile("cli"));
|
||||
|
@ -82,7 +82,7 @@ unitTest(
|
|||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true } },
|
||||
{ permissions: { read: true } },
|
||||
function readFileSyncDoesNotLeakResources() {
|
||||
const resourcesBefore = Deno.resources();
|
||||
assertThrows(() => Deno.readFileSync("cli"));
|
||||
|
@ -91,7 +91,7 @@ unitTest(
|
|||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true } },
|
||||
{ permissions: { read: true } },
|
||||
async function readFileWithAbortSignal() {
|
||||
const ac = new AbortController();
|
||||
queueMicrotask(() => ac.abort());
|
||||
|
@ -104,7 +104,7 @@ unitTest(
|
|||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true } },
|
||||
{ permissions: { read: true } },
|
||||
async function readTextileWithAbortSignal() {
|
||||
const ac = new AbortController();
|
||||
queueMicrotask(() => ac.abort());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue