summaryrefslogtreecommitdiff
path: root/js/symlink_test.ts
blob: 84dc452794f2eca0e2a51ae1972a24388576ed3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { 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());
  }
});