mirror of
https://github.com/denoland/deno.git
synced 2025-10-02 15:14:33 +00:00
Add ability to unit test by permissions.
This commit is contained in:
parent
722c7e4a1b
commit
e13f3c10ca
7 changed files with 113 additions and 25 deletions
|
@ -3,8 +3,7 @@
|
|||
// But it can also be run manually:
|
||||
// ./deno tests.ts
|
||||
|
||||
import { test, assert, assertEqual } from "./testing/testing.ts";
|
||||
import { readFileSync } from "deno";
|
||||
import { test, testPerm, assert, assertEqual } from "./test_util.ts";
|
||||
import * as deno from "deno";
|
||||
|
||||
import "./compiler_test.ts";
|
||||
|
@ -15,7 +14,7 @@ test(async function tests_test() {
|
|||
});
|
||||
|
||||
test(async function tests_readFileSync() {
|
||||
const data = readFileSync("package.json");
|
||||
const data = deno.readFileSync("package.json");
|
||||
if (!data.byteLength) {
|
||||
throw Error(
|
||||
`Expected positive value for data.byteLength ${data.byteLength}`
|
||||
|
@ -32,7 +31,7 @@ test(function tests_readFileSync_NotFound() {
|
|||
let caughtError = false;
|
||||
let data;
|
||||
try {
|
||||
data = readFileSync("bad_filename");
|
||||
data = deno.readFileSync("bad_filename");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof deno.NotFound);
|
||||
|
@ -48,14 +47,14 @@ test(function writeFileSyncSuccess() {
|
|||
const dataWritten = enc.encode("Hello");
|
||||
const filename = "TEMPDIR/test.txt";
|
||||
deno.writeFileSync(filename, dataWritten, 0o666);
|
||||
const dataRead = readFileSync(filename);
|
||||
const dataRead = deno.readFileSync(filename);
|
||||
assertEqual(dataRead, dataWritten);
|
||||
});
|
||||
*/
|
||||
|
||||
// For this test to pass we need --allow-write permission.
|
||||
// Otherwise it will fail with deno.PermissionDenied instead of deno.NotFound.
|
||||
test(function writeFileSyncFail() {
|
||||
testPerm({ write: true }, function writeFileSyncFail() {
|
||||
const enc = new TextEncoder();
|
||||
const data = enc.encode("Hello");
|
||||
const filename = "/baddir/test.txt";
|
||||
|
@ -71,7 +70,7 @@ test(function writeFileSyncFail() {
|
|||
assert(caughtError);
|
||||
});
|
||||
|
||||
test(async function tests_fetch() {
|
||||
testPerm({ net: true }, async function tests_fetch() {
|
||||
const response = await fetch("http://localhost:4545/package.json");
|
||||
const json = await response.json();
|
||||
assertEqual(json.name, "deno");
|
||||
|
@ -84,7 +83,7 @@ test(async function tests_writeFileSync() {
|
|||
// TODO need ability to get tmp dir.
|
||||
const fn = "/tmp/test.txt";
|
||||
writeFileSync("/tmp/test.txt", data, 0o666);
|
||||
const dataRead = readFileSync("/tmp/test.txt");
|
||||
const dataRead = deno.readFileSync("/tmp/test.txt");
|
||||
const dec = new TextDecoder("utf-8");
|
||||
const actual = dec.decode(dataRead);
|
||||
assertEqual("Hello", actual);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue