0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/symlink_test.ts

81 lines
2.4 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(): void {
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) {
2019-09-09 23:39:42 -04:00
assertEquals(Deno.build.os, "win");
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(): void {
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.
// Symlink with type should succeed on other platforms with type ignored
testPerm({ write: true }, function symlinkSyncNotImplemented(): void {
2019-04-24 20:34:33 -04:00
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";
2018-09-19 00:38:24 -04:00
let err;
try {
2019-04-24 20:34:33 -04:00
Deno.symlinkSync(oldname, newname, "dir");
2018-09-19 00:38:24 -04:00
} catch (e) {
err = e;
}
if (err) {
2019-09-09 23:39:42 -04:00
assertEquals(Deno.build.os, "win");
assertEquals(err.message, "Not implemented");
}
2018-09-19 00:38:24 -04:00
});
testPerm({ read: true, write: true }, async function symlinkSuccess(): Promise<
void
> {
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());
}
});