diff options
Diffstat (limited to 'js/read_file_test.ts')
-rw-r--r-- | js/read_file_test.ts | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/js/read_file_test.ts b/js/read_file_test.ts index db35dd702..34b391345 100644 --- a/js/read_file_test.ts +++ b/js/read_file_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { test, assert, assertEqual } from "./test_util.ts"; +import { testPerm, assert, assertEqual } from "./test_util.ts"; import * as deno from "deno"; -test(function readFileSyncSuccess() { +testPerm({ read: true }, function readFileSyncSuccess() { const data = deno.readFileSync("package.json"); assert(data.byteLength > 0); const decoder = new TextDecoder("utf-8"); @@ -11,7 +11,19 @@ test(function readFileSyncSuccess() { assertEqual(pkg.name, "deno"); }); -test(function readFileSyncNotFound() { +testPerm({ read: false }, function readFileSyncPerm() { + let caughtError = false; + try { + const data = deno.readFileSync("package.json"); + } catch (e) { + caughtError = true; + assertEqual(e.kind, deno.ErrorKind.PermissionDenied); + assertEqual(e.name, "PermissionDenied"); + } + assert(caughtError); +}); + +testPerm({ read: true }, function readFileSyncNotFound() { let caughtError = false; let data; try { @@ -24,7 +36,7 @@ test(function readFileSyncNotFound() { assert(data === undefined); }); -test(async function readFileSuccess() { +testPerm({ read: true }, async function readFileSuccess() { const data = await deno.readFile("package.json"); assert(data.byteLength > 0); const decoder = new TextDecoder("utf-8"); @@ -32,3 +44,15 @@ test(async function readFileSuccess() { const pkg = JSON.parse(json); assertEqual(pkg.name, "deno"); }); + +testPerm({ read: false }, async function readFilePerm() { + let caughtError = false; + try { + await deno.readFile("package.json"); + } catch (e) { + caughtError = true; + assertEqual(e.kind, deno.ErrorKind.PermissionDenied); + assertEqual(e.name, "PermissionDenied"); + } + assert(caughtError); +}); |