summaryrefslogtreecommitdiff
path: root/js/symlink_test.ts
diff options
context:
space:
mode:
authorMani Maghsoudlou <manidlou@gmail.com>2018-09-18 21:38:24 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-09-18 21:38:24 -0700
commit017ef096dfb0592d828804175e582895a3f39954 (patch)
tree57352559b6f044859332a646c4e6d5e28a447851 /js/symlink_test.ts
parentd19268b2bf43d454d825ba645b37e6f764ee42f2 (diff)
Implement deno.symlink() (#742)
Diffstat (limited to 'js/symlink_test.ts')
-rw-r--r--js/symlink_test.ts71
1 files changed, 71 insertions, 0 deletions
diff --git a/js/symlink_test.ts b/js/symlink_test.ts
new file mode 100644
index 000000000..a3203ac6e
--- /dev/null
+++ b/js/symlink_test.ts
@@ -0,0 +1,71 @@
+// 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 symlinkSyncSuccess() {
+ const testDir = deno.makeTempDirSync() + "/test-symlink-sync";
+ const oldname = testDir + "/oldname";
+ const newname = testDir + "/newname";
+ deno.mkdirSync(oldname);
+ let errOnWindows;
+ // Just for now, until we implement symlink for Windows.
+ try {
+ deno.symlinkSync(oldname, newname);
+ } catch (e) {
+ errOnWindows = e;
+ }
+ if (errOnWindows) {
+ assertEqual(errOnWindows.kind, deno.ErrorKind.Other);
+ assertEqual(errOnWindows.message, "Not implemented");
+ } else {
+ const newNameInfoLStat = deno.lstatSync(newname);
+ const newNameInfoStat = deno.statSync(newname);
+ assert(newNameInfoLStat.isSymlink());
+ assert(newNameInfoStat.isDirectory());
+ }
+});
+
+testPerm({ write: false }, function symlinkSyncPerm() {
+ let err;
+ try {
+ deno.symlinkSync("oldbaddir", "newbaddir");
+ } catch (e) {
+ err = e;
+ }
+ assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
+ assertEqual(err.name, "PermissionDenied");
+});
+
+// Just for now, until we implement symlink for Windows.
+testPerm({ write: true }, function symlinkSyncNotImplemented() {
+ let err;
+ try {
+ deno.symlinkSync("oldname", "newname", "dir");
+ } catch (e) {
+ err = e;
+ }
+ assertEqual(err.message, "Not implemented");
+});
+
+testPerm({ write: true }, async function symlinkSuccess() {
+ const testDir = deno.makeTempDirSync() + "/test-symlink";
+ const oldname = testDir + "/oldname";
+ const newname = testDir + "/newname";
+ deno.mkdirSync(oldname);
+ let errOnWindows;
+ // Just for now, until we implement symlink for Windows.
+ try {
+ await deno.symlink(oldname, newname);
+ } catch (e) {
+ errOnWindows = e;
+ }
+ if (errOnWindows) {
+ assertEqual(errOnWindows.kind, deno.ErrorKind.Other);
+ assertEqual(errOnWindows.message, "Not implemented");
+ } else {
+ const newNameInfoLStat = deno.lstatSync(newname);
+ const newNameInfoStat = deno.statSync(newname);
+ assert(newNameInfoLStat.isSymlink());
+ assert(newNameInfoStat.isDirectory());
+ }
+});