2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-02-08 15:59:38 -05:00
|
|
|
import { test, testPerm, assert, assertEqual } from "./test_util.ts";
|
2018-09-19 00:38:24 -04:00
|
|
|
import * as deno from "deno";
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, function symlinkSyncSuccess() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const testDir = deno.makeTempDirSync();
|
2018-09-19 00:38:24 -04:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
test(function symlinkSyncPerm() {
|
2018-09-19 00:38:24 -04:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, async function symlinkSuccess() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const testDir = deno.makeTempDirSync();
|
2018-09-19 00:38:24 -04:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
});
|