deno/cli/js/symlink_test.ts

81 lines
2.4 KiB
TypeScript
Raw Normal View History

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