2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 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-12 11:44:58 -04:00
|
|
|
import * as deno from "deno";
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, function renameSyncSuccess() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const testDir = deno.makeTempDirSync();
|
2018-09-12 11:44:58 -04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: false }, function renameSyncPerm() {
|
2018-09-12 11:44:58 -04:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, async function renameSuccess() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const testDir = deno.makeTempDirSync();
|
2018-09-12 11:44:58 -04:00
|
|
|
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);
|
|
|
|
});
|