1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/js/rename_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

60 lines
1.6 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 renameSyncSuccess() {
const testDir = deno.makeTempDirSync();
const oldpath = testDir + "/oldpath";
const newpath = testDir + "/newpath";
deno.mkdirSync(oldpath);
deno.renameSync(oldpath, newpath);
const newPathInfo = deno.statSync(newpath);
assert(newPathInfo.isDirectory());
let caughtErr = false;
let oldPathInfo;
try {
oldPathInfo = deno.statSync(oldpath);
} catch (e) {
caughtErr = true;
assertEqual(e.kind, deno.ErrorKind.NotFound);
}
assert(caughtErr);
assertEqual(oldPathInfo, undefined);
});
testPerm({ read: true, write: false }, function renameSyncPerm() {
let err;
try {
const oldpath = "/oldbaddir";
const newpath = "/newbaddir";
deno.renameSync(oldpath, newpath);
} catch (e) {
err = e;
}
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
assertEqual(err.name, "PermissionDenied");
});
testPerm({ read: true, write: true }, async function renameSuccess() {
const testDir = deno.makeTempDirSync();
const oldpath = testDir + "/oldpath";
const newpath = testDir + "/newpath";
deno.mkdirSync(oldpath);
await deno.rename(oldpath, newpath);
const newPathInfo = deno.statSync(newpath);
assert(newPathInfo.isDirectory());
let caughtErr = false;
let oldPathInfo;
try {
oldPathInfo = deno.statSync(oldpath);
} catch (e) {
caughtErr = true;
assertEqual(e.kind, deno.ErrorKind.NotFound);
}
assert(caughtErr);
assertEqual(oldPathInfo, undefined);
});