1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00
denoland-deno/js/mkdir_test.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-10 05:48:36 -04:00
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { test, testPerm, assert, assertEqual } from "./test_util.ts";
import * as deno from "deno";
testPerm({ write: true }, function mkdirSyncSuccess() {
const path = deno.makeTempDirSync() + "/dir/subdir";
deno.mkdirSync(path);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});
testPerm({ write: true }, function mkdirSyncMode() {
const path = deno.makeTempDirSync() + "/dir/subdir";
deno.mkdirSync(path, 0o755); // no perm for x
const pathInfo = deno.statSync(path);
if (pathInfo.mode !== null) {
// Skip windows
assertEqual(pathInfo.mode & 0o777, 0o755);
}
});
2018-09-10 05:48:36 -04:00
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({ write: true }, async function mkdirSuccess() {
const path = deno.makeTempDirSync() + "/dir/subdir";
await deno.mkdir(path);
const pathInfo = deno.statSync(path);
assert(pathInfo.isDirectory());
});