summaryrefslogtreecommitdiff
path: root/js/rename_test.ts
diff options
context:
space:
mode:
authorMani Maghsoudlou <manidlou@gmail.com>2018-09-12 08:44:58 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-09-12 11:44:58 -0400
commit88d42f0b189a1daa3fb44eb24ecad77823557d9f (patch)
treeac4d166271d9708472b16150f5f6dcc712095fcb /js/rename_test.ts
parent26081a32dfaf34fdc8b6cf53222c15f3d4e4f30d (diff)
Implement deno.rename() (#731)
Diffstat (limited to 'js/rename_test.ts')
-rw-r--r--js/rename_test.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/js/rename_test.ts b/js/rename_test.ts
new file mode 100644
index 000000000..450760dae
--- /dev/null
+++ b/js/rename_test.ts
@@ -0,0 +1,60 @@
+// 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 renameSyncSuccess() {
+ const testDir = deno.makeTempDirSync() + "/test-rename-sync";
+ 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({ 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({ write: true }, async function renameSuccess() {
+ const testDir = deno.makeTempDirSync() + "/test-rename";
+ 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);
+});