1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/js/stat_test.ts

174 lines
4.5 KiB
TypeScript
Raw Normal View History

2019-01-21 14:03:30 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { testPerm, assert, assertEqual } from "./test_util.ts";
2018-09-11 15:38:53 -04:00
import * as deno from "deno";
// TODO Add tests for modified, accessed, and created fields once there is a way
// to create temp files.
testPerm({ read: true }, async function statSyncSuccess() {
2018-09-11 15:38:53 -04:00
const packageInfo = deno.statSync("package.json");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
const testingInfo = deno.statSync("testing");
assert(testingInfo.isDirectory());
assert(!testingInfo.isSymlink());
const srcInfo = deno.statSync("src");
assert(srcInfo.isDirectory());
assert(!srcInfo.isSymlink());
});
testPerm({ read: false }, async function statSyncPerm() {
let caughtError = false;
try {
deno.statSync("package.json");
} catch (e) {
caughtError = true;
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
assertEqual(e.name, "PermissionDenied");
}
assert(caughtError);
});
testPerm({ read: true }, async function statSyncNotFound() {
2018-09-11 15:38:53 -04:00
let caughtError = false;
let badInfo;
try {
badInfo = deno.statSync("bad_file_name");
} catch (err) {
caughtError = true;
assertEqual(err.kind, deno.ErrorKind.NotFound);
assertEqual(err.name, "NotFound");
}
assert(caughtError);
assertEqual(badInfo, undefined);
});
testPerm({ read: true }, async function lstatSyncSuccess() {
2018-09-11 15:38:53 -04:00
const packageInfo = deno.lstatSync("package.json");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
const testingInfo = deno.lstatSync("testing");
assert(!testingInfo.isDirectory());
assert(testingInfo.isSymlink());
const srcInfo = deno.lstatSync("src");
assert(srcInfo.isDirectory());
assert(!srcInfo.isSymlink());
});
testPerm({ read: false }, async function lstatSyncPerm() {
let caughtError = false;
try {
deno.lstatSync("package.json");
} catch (e) {
caughtError = true;
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
assertEqual(e.name, "PermissionDenied");
}
assert(caughtError);
});
testPerm({ read: true }, async function lstatSyncNotFound() {
2018-09-11 15:38:53 -04:00
let caughtError = false;
let badInfo;
try {
badInfo = deno.lstatSync("bad_file_name");
} catch (err) {
caughtError = true;
assertEqual(err.kind, deno.ErrorKind.NotFound);
assertEqual(err.name, "NotFound");
}
assert(caughtError);
assertEqual(badInfo, undefined);
});
testPerm({ read: true }, async function statSuccess() {
2018-09-11 15:38:53 -04:00
const packageInfo = await deno.stat("package.json");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
const testingInfo = await deno.stat("testing");
assert(testingInfo.isDirectory());
assert(!testingInfo.isSymlink());
const srcInfo = await deno.stat("src");
assert(srcInfo.isDirectory());
assert(!srcInfo.isSymlink());
});
testPerm({ read: false }, async function statPerm() {
let caughtError = false;
try {
await deno.stat("package.json");
} catch (e) {
caughtError = true;
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
assertEqual(e.name, "PermissionDenied");
}
assert(caughtError);
});
testPerm({ read: true }, async function statNotFound() {
2018-09-11 15:38:53 -04:00
let caughtError = false;
let badInfo;
try {
badInfo = await deno.stat("bad_file_name");
} catch (err) {
caughtError = true;
assertEqual(err.kind, deno.ErrorKind.NotFound);
assertEqual(err.name, "NotFound");
}
assert(caughtError);
assertEqual(badInfo, undefined);
});
testPerm({ read: true }, async function lstatSuccess() {
2018-09-11 15:38:53 -04:00
const packageInfo = await deno.lstat("package.json");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
const testingInfo = await deno.lstat("testing");
assert(!testingInfo.isDirectory());
assert(testingInfo.isSymlink());
const srcInfo = await deno.lstat("src");
assert(srcInfo.isDirectory());
assert(!srcInfo.isSymlink());
});
testPerm({ read: false }, async function lstatPerm() {
let caughtError = false;
try {
await deno.lstat("package.json");
} catch (e) {
caughtError = true;
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
assertEqual(e.name, "PermissionDenied");
}
assert(caughtError);
});
testPerm({ read: true }, async function lstatNotFound() {
2018-09-11 15:38:53 -04:00
let caughtError = false;
let badInfo;
try {
badInfo = await deno.lstat("bad_file_name");
} catch (err) {
caughtError = true;
assertEqual(err.kind, deno.ErrorKind.NotFound);
assertEqual(err.name, "NotFound");
}
assert(caughtError);
assertEqual(badInfo, undefined);
});