summaryrefslogtreecommitdiff
path: root/js/read_link_test.ts
diff options
context:
space:
mode:
authorMani Maghsoudlou <manidlou@gmail.com>2018-09-24 21:20:49 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-09-25 00:20:49 -0400
commitad5065e23ec33af1422eeffdbb877ef8fd5f6da4 (patch)
tree5b90e2c1e59ad97ef0aa3f93868f80c90b8a365b /js/read_link_test.ts
parentd957f8ebc24bcbdb94c0c5297c0072aa8d2ebec8 (diff)
Implement deno.readlink() (#797)
Diffstat (limited to 'js/read_link_test.ts')
-rw-r--r--js/read_link_test.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/js/read_link_test.ts b/js/read_link_test.ts
new file mode 100644
index 000000000..2df6b30d0
--- /dev/null
+++ b/js/read_link_test.ts
@@ -0,0 +1,44 @@
+// 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 readlinkSyncSuccess() {
+ const testDir = deno.makeTempDirSync() + "/test-readlink-sync";
+ const target = testDir + "/target";
+ const symlink = testDir + "/symln";
+ deno.mkdirSync(target);
+ // TODO Add test for Windows once symlink is implemented for Windows.
+ // See https://github.com/denoland/deno/issues/815.
+ if (deno.platform !== "win32") {
+ deno.symlinkSync(target, symlink);
+ const targetPath = deno.readlinkSync(symlink);
+ assertEqual(targetPath, target);
+ }
+});
+
+test(function readlinkSyncNotFound() {
+ let caughtError = false;
+ let data;
+ try {
+ data = deno.readlinkSync("bad_filename");
+ } catch (e) {
+ caughtError = true;
+ assertEqual(e.kind, deno.ErrorKind.NotFound);
+ }
+ assert(caughtError);
+ assertEqual(data, undefined);
+});
+
+testPerm({ write: true }, async function readlinkSuccess() {
+ const testDir = deno.makeTempDirSync() + "/test-readlink";
+ const target = testDir + "/target";
+ const symlink = testDir + "/symln";
+ deno.mkdirSync(target);
+ // TODO Add test for Windows once symlink is implemented for Windows.
+ // See https://github.com/denoland/deno/issues/815.
+ if (deno.platform !== "win32") {
+ deno.symlinkSync(target, symlink);
+ const targetPath = await deno.readlink(symlink);
+ assertEqual(targetPath, target);
+ }
+});