1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/js/symlink_test.ts

71 lines
2.1 KiB
TypeScript
Raw Normal View History

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