diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-02-28 15:47:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 15:47:54 +0100 |
commit | a13b0e27279e54205adb53cdaf2415c825e77714 (patch) | |
tree | f108a6b2d0755cc435c7e19d2e38b8f6b8405328 /cli/tests | |
parent | 7255cc9bc089e1257c2119e4c8a089c0b4970e64 (diff) |
rewrite permission revoke test as integration test (#4164)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/057_revoke_permissions.out | 10 | ||||
-rw-r--r-- | cli/tests/057_revoke_permissions.ts | 36 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 5 |
3 files changed, 51 insertions, 0 deletions
diff --git a/cli/tests/057_revoke_permissions.out b/cli/tests/057_revoke_permissions.out new file mode 100644 index 000000000..1f12d3b93 --- /dev/null +++ b/cli/tests/057_revoke_permissions.out @@ -0,0 +1,10 @@ +running 7 tests +OK runGranted [WILDCARD] +OK readGranted [WILDCARD] +OK writeGranted [WILDCARD] +OK netGranted [WILDCARD] +OK envGranted [WILDCARD] +OK pluginGranted [WILDCARD] +OK hrtimeGranted [WILDCARD] + +test result: OK 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out [WILDCARD]
\ No newline at end of file diff --git a/cli/tests/057_revoke_permissions.ts b/cli/tests/057_revoke_permissions.ts new file mode 100644 index 000000000..4481dbfd9 --- /dev/null +++ b/cli/tests/057_revoke_permissions.ts @@ -0,0 +1,36 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +const knownPermissions: Deno.PermissionName[] = [ + "run", + "read", + "write", + "net", + "env", + "plugin", + "hrtime" +]; + +export function assert(cond: unknown): asserts cond { + if (!cond) { + throw Error("Assertion failed"); + } +} + +function genFunc(grant: Deno.PermissionName): () => Promise<void> { + const gen: () => Promise<void> = async function Granted(): Promise<void> { + const status0 = await Deno.permissions.query({ name: grant }); + assert(status0 != null); + assert(status0.state === "granted"); + + const status1 = await Deno.permissions.revoke({ name: grant }); + assert(status1 != null); + assert(status1.state === "prompt"); + }; + // Properly name these generated functions. + Object.defineProperty(gen, "name", { value: grant + "Granted" }); + return gen; +} + +for (const grant of knownPermissions) { + Deno.test(genFunc(grant)); +} diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 843f56a7f..434a55c08 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -936,6 +936,11 @@ itest!(_056_make_temp_file_write_perm { output: "056_make_temp_file_write_perm.out", }); +itest!(_057_revoke_permissions { + args: "test -A 057_revoke_permissions.ts", + output: "057_revoke_permissions.out", +}); + itest!(js_import_detect { args: "run --reload js_import_detect.ts", output: "js_import_detect.ts.out", |