0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/mkdir_test.ts
Dmitry Sharshakov 9ab03389f0 Add --allow-read (#1689)
Co-authored-by: Greg Altman <g.s.altman@gmail.com>
2019-02-08 15:59:38 -05:00

63 lines
1.8 KiB
TypeScript

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { testPerm, assert, assertEqual } from "./test_util.ts";
import * as deno from "deno";
testPerm({ read: true, write: true }, function mkdirSyncSuccess() {
const path = deno.makeTempDirSync() + "/dir";
deno.mkdirSync(path);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});
testPerm({ read: true, write: true }, function mkdirSyncMode() {
const path = deno.makeTempDirSync() + "/dir";
deno.mkdirSync(path, false, 0o755); // no perm for x
const pathInfo = deno.statSync(path);
if (pathInfo.mode !== null) {
// Skip windows
assertEqual(pathInfo.mode & 0o777, 0o755);
}
});
testPerm({ write: false }, function mkdirSyncPerm() {
let err;
try {
deno.mkdirSync("/baddir");
} catch (e) {
err = e;
}
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
assertEqual(err.name, "PermissionDenied");
});
testPerm({ read: true, write: true }, async function mkdirSuccess() {
const path = deno.makeTempDirSync() + "/dir";
await deno.mkdir(path);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});
testPerm({ write: true }, function mkdirErrIfExists() {
let err;
try {
deno.mkdirSync(".");
} catch (e) {
err = e;
}
assertEqual(err.kind, deno.ErrorKind.AlreadyExists);
assertEqual(err.name, "AlreadyExists");
});
testPerm({ read: true, write: true }, function mkdirSyncRecursive() {
const path = deno.makeTempDirSync() + "/nested/directory";
deno.mkdirSync(path, true);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});
testPerm({ read: true, write: true }, async function mkdirRecursive() {
const path = deno.makeTempDirSync() + "/nested/directory";
await deno.mkdir(path, true);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});