2024-04-29 10:08:27 -04:00
|
|
|
import { assertEquals } from "jsr:@std/assert";
|
2022-03-11 17:07:02 -05:00
|
|
|
|
|
|
|
const permissions: Deno.PermissionName[] = [
|
|
|
|
"read",
|
|
|
|
"write",
|
|
|
|
"net",
|
|
|
|
"env",
|
|
|
|
"run",
|
|
|
|
"ffi",
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const name of permissions) {
|
|
|
|
Deno.bench({
|
|
|
|
name: `${name} false`,
|
|
|
|
permissions: {
|
|
|
|
[name]: false,
|
|
|
|
},
|
|
|
|
async fn() {
|
2022-03-20 17:46:39 -04:00
|
|
|
for await (const n of permissions) {
|
|
|
|
const status = await Deno.permissions.query({ name: n });
|
|
|
|
assertEquals(status.state, "prompt");
|
|
|
|
}
|
2022-03-11 17:07:02 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.bench({
|
|
|
|
name: `${name} true`,
|
|
|
|
permissions: {
|
|
|
|
[name]: true,
|
|
|
|
},
|
|
|
|
async fn() {
|
2022-03-20 17:46:39 -04:00
|
|
|
for await (const n of permissions) {
|
|
|
|
const status = await Deno.permissions.query({ name: n });
|
|
|
|
if (n === name) {
|
|
|
|
assertEquals(status.state, "granted");
|
|
|
|
} else {
|
|
|
|
assertEquals(status.state, "prompt");
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 17:07:02 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|