mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
f3751e498f
This commits adds adds "permissions" option to the test definitions which allows tests to run with different permission sets than the process's permission. The change will only be in effect within the test function, once the test has completed the original process permission set is restored. Test permissions cannot exceed the process's permission. You can only narrow or drop permissions, failure to acquire a permission results in an error being thrown and the test case will fail.
35 lines
678 B
TypeScript
35 lines
678 B
TypeScript
import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
|
|
|
|
const permissions: Deno.PermissionName[] = [
|
|
"read",
|
|
"write",
|
|
"net",
|
|
"env",
|
|
"run",
|
|
"plugin",
|
|
"hrtime",
|
|
];
|
|
|
|
for (const name of permissions) {
|
|
Deno.test({
|
|
name: `${name} false`,
|
|
permissions: {
|
|
[name]: false,
|
|
},
|
|
async fn() {
|
|
const status = await Deno.permissions.query({ name });
|
|
assertEquals(status.state, "denied");
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: `${name} true`,
|
|
permissions: {
|
|
[name]: true,
|
|
},
|
|
async fn() {
|
|
const status = await Deno.permissions.query({ name });
|
|
assertEquals(status.state, "granted");
|
|
},
|
|
});
|
|
}
|