diff options
author | Dmitry Sharshakov <sh7dm@outlook.com> | 2019-02-08 23:59:38 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-08 15:59:38 -0500 |
commit | 9ab03389f047e5520c184b9fce4cd5fb2e4804bd (patch) | |
tree | c1b3295aa6788595e4b73d28aeba0b8fdc8f3205 /js/read_dir_test.ts | |
parent | 3abaf9edb6877c328402b94fa0bcb6a9e0bbe86d (diff) |
Add --allow-read (#1689)
Co-authored-by: Greg Altman <g.s.altman@gmail.com>
Diffstat (limited to 'js/read_dir_test.ts')
-rw-r--r-- | js/read_dir_test.ts | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/js/read_dir_test.ts b/js/read_dir_test.ts index d025c6ec5..77f33f714 100644 --- a/js/read_dir_test.ts +++ b/js/read_dir_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { test, testPerm, assert, assertEqual } from "./test_util.ts"; +import { testPerm, assert, assertEqual } from "./test_util.ts"; import * as deno from "deno"; import { FileInfo } from "deno"; @@ -22,12 +22,24 @@ function assertSameContent(files: FileInfo[]) { assertEqual(counter, 2); } -test(function readDirSyncSuccess() { +testPerm({ read: true }, function readDirSyncSuccess() { const files = deno.readDirSync("tests/"); assertSameContent(files); }); -test(function readDirSyncNotDir() { +testPerm({ read: false }, function readDirSyncPerm() { + let caughtError = false; + try { + const files = deno.readDirSync("tests/"); + } catch (e) { + caughtError = true; + assertEqual(e.kind, deno.ErrorKind.PermissionDenied); + assertEqual(e.name, "PermissionDenied"); + } + assert(caughtError); +}); + +testPerm({ read: true }, function readDirSyncNotDir() { let caughtError = false; let src; @@ -41,7 +53,7 @@ test(function readDirSyncNotDir() { assertEqual(src, undefined); }); -test(function readDirSyncNotFound() { +testPerm({ read: true }, function readDirSyncNotFound() { let caughtError = false; let src; @@ -55,7 +67,19 @@ test(function readDirSyncNotFound() { assertEqual(src, undefined); }); -test(async function readDirSuccess() { +testPerm({ read: true }, async function readDirSuccess() { const files = await deno.readDir("tests/"); assertSameContent(files); }); + +testPerm({ read: false }, async function readDirPerm() { + let caughtError = false; + try { + const files = await deno.readDir("tests/"); + } catch (e) { + caughtError = true; + assertEqual(e.kind, deno.ErrorKind.PermissionDenied); + assertEqual(e.name, "PermissionDenied"); + } + assert(caughtError); +}); |