2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-06 20:48:46 -05:00
|
|
|
import { test, testPerm, assert, assertEquals } from "./test_util.ts";
|
2018-09-19 00:38:24 -04:00
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, function symlinkSyncSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
2018-09-19 00:38:24 -04:00
|
|
|
const oldname = testDir + "/oldname";
|
|
|
|
const newname = testDir + "/newname";
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.mkdirSync(oldname);
|
2018-09-19 00:38:24 -04:00
|
|
|
let errOnWindows;
|
|
|
|
// Just for now, until we implement symlink for Windows.
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.symlinkSync(oldname, newname);
|
2018-09-19 00:38:24 -04:00
|
|
|
} catch (e) {
|
|
|
|
errOnWindows = e;
|
|
|
|
}
|
|
|
|
if (errOnWindows) {
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
|
|
assertEquals(errOnWindows.message, "Not implemented");
|
2018-09-19 00:38:24 -04:00
|
|
|
} else {
|
2019-02-12 10:08:56 -05:00
|
|
|
const newNameInfoLStat = Deno.lstatSync(newname);
|
|
|
|
const newNameInfoStat = Deno.statSync(newname);
|
2018-09-19 00:38:24 -04:00
|
|
|
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 {
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.symlinkSync("oldbaddir", "newbaddir");
|
2018-09-19 00:38:24 -04:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(err.name, "PermissionDenied");
|
2018-09-19 00:38:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Just for now, until we implement symlink for Windows.
|
|
|
|
testPerm({ write: true }, function symlinkSyncNotImplemented() {
|
|
|
|
let err;
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.symlinkSync("oldname", "newname", "dir");
|
2018-09-19 00:38:24 -04:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.message, "Not implemented");
|
2018-09-19 00:38:24 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, async function symlinkSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
2018-09-19 00:38:24 -04:00
|
|
|
const oldname = testDir + "/oldname";
|
|
|
|
const newname = testDir + "/newname";
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.mkdirSync(oldname);
|
2018-09-19 00:38:24 -04:00
|
|
|
let errOnWindows;
|
|
|
|
// Just for now, until we implement symlink for Windows.
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
await Deno.symlink(oldname, newname);
|
2018-09-19 00:38:24 -04:00
|
|
|
} catch (e) {
|
|
|
|
errOnWindows = e;
|
|
|
|
}
|
|
|
|
if (errOnWindows) {
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
|
|
assertEquals(errOnWindows.message, "Not implemented");
|
2018-09-19 00:38:24 -04:00
|
|
|
} else {
|
2019-02-12 10:08:56 -05:00
|
|
|
const newNameInfoLStat = Deno.lstatSync(newname);
|
|
|
|
const newNameInfoStat = Deno.statSync(newname);
|
2018-09-19 00:38:24 -04:00
|
|
|
assert(newNameInfoLStat.isSymlink());
|
|
|
|
assert(newNameInfoStat.isDirectory());
|
|
|
|
}
|
|
|
|
});
|