2018-09-10 05:48:36 -04:00
|
|
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
2019-01-12 09:16:18 -05:00
|
|
|
import { testPerm, assert, assertEqual } from "./test_util.ts";
|
2018-09-10 05:48:36 -04:00
|
|
|
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());
|
|
|
|
});
|
|
|
|
|
2018-09-14 15:30:43 -04:00
|
|
|
testPerm({ write: true }, function mkdirSyncMode() {
|
|
|
|
const path = deno.makeTempDirSync() + "/dir/subdir";
|
|
|
|
deno.mkdirSync(path, 0o755); // no perm for x
|
|
|
|
const pathInfo = deno.statSync(path);
|
2018-09-16 16:35:16 -04:00
|
|
|
if (pathInfo.mode !== null) {
|
|
|
|
// Skip windows
|
2018-09-14 15:30:43 -04:00
|
|
|
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());
|
|
|
|
});
|