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-04-21 16:40:10 -04:00
|
|
|
testPerm({ read: true, write: true }, function symlinkSyncSuccess(): void {
|
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-04-23 09:47:29 -04:00
|
|
|
assertEquals(Deno.platform.os, "win");
|
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-04-21 16:40:10 -04:00
|
|
|
test(function symlinkSyncPerm(): void {
|
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.
|
2019-04-23 09:47:29 -04:00
|
|
|
// Symlink with type should succeed on other platforms with type ignored
|
2019-04-21 16:40:10 -04:00
|
|
|
testPerm({ write: true }, function symlinkSyncNotImplemented(): void {
|
2018-09-19 00:38:24 -04:00
|
|
|
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-04-23 09:47:29 -04:00
|
|
|
if (err) {
|
|
|
|
assertEquals(Deno.platform.os, "win");
|
|
|
|
assertEquals(err.message, "Not implemented");
|
|
|
|
}
|
2018-09-19 00:38:24 -04:00
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
testPerm({ read: true, write: true }, async function symlinkSuccess(): Promise<
|
|
|
|
void
|
|
|
|
> {
|
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());
|
|
|
|
}
|
|
|
|
});
|