2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-06-24 18:57:08 -04:00
|
|
|
import {
|
|
|
|
unitTest,
|
|
|
|
assertEquals,
|
|
|
|
assertThrows,
|
|
|
|
assertThrowsAsync,
|
|
|
|
} from "./test_util.ts";
|
2018-09-25 00:20:49 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
2020-04-29 16:39:37 -04:00
|
|
|
function readLinkSyncSuccess(): void {
|
2020-03-04 11:31:14 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const target = testDir + "/target";
|
|
|
|
const symlink = testDir + "/symln";
|
|
|
|
Deno.mkdirSync(target);
|
|
|
|
// TODO Add test for Windows once symlink is implemented for Windows.
|
|
|
|
// See https://github.com/denoland/deno/issues/815.
|
2020-04-28 12:35:23 -04:00
|
|
|
if (Deno.build.os !== "windows") {
|
2020-03-04 11:31:14 -05:00
|
|
|
Deno.symlinkSync(target, symlink);
|
2020-04-29 16:39:37 -04:00
|
|
|
const targetPath = Deno.readLinkSync(symlink);
|
2020-03-04 11:31:14 -05:00
|
|
|
assertEquals(targetPath, target);
|
|
|
|
}
|
2018-09-25 00:20:49 -04:00
|
|
|
}
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2018-09-25 00:20:49 -04:00
|
|
|
|
2020-04-29 16:39:37 -04:00
|
|
|
unitTest({ perms: { read: false } }, function readLinkSyncPerm(): void {
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
2020-04-29 16:39:37 -04:00
|
|
|
Deno.readLinkSync("/symlink");
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2019-02-08 15:59:38 -05:00
|
|
|
});
|
|
|
|
|
2020-04-29 16:39:37 -04:00
|
|
|
unitTest({ perms: { read: true } }, function readLinkSyncNotFound(): void {
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
|
|
|
Deno.readLinkSync("bad_filename");
|
|
|
|
}, Deno.errors.NotFound);
|
2018-09-25 00:20:49 -04:00
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
2020-04-29 16:39:37 -04:00
|
|
|
async function readLinkSuccess(): Promise<void> {
|
2020-03-04 11:31:14 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const target = testDir + "/target";
|
|
|
|
const symlink = testDir + "/symln";
|
|
|
|
Deno.mkdirSync(target);
|
|
|
|
// TODO Add test for Windows once symlink is implemented for Windows.
|
|
|
|
// See https://github.com/denoland/deno/issues/815.
|
2020-04-28 12:35:23 -04:00
|
|
|
if (Deno.build.os !== "windows") {
|
2020-03-04 11:31:14 -05:00
|
|
|
Deno.symlinkSync(target, symlink);
|
2020-04-29 16:39:37 -04:00
|
|
|
const targetPath = await Deno.readLink(symlink);
|
2020-03-04 11:31:14 -05:00
|
|
|
assertEquals(targetPath, target);
|
|
|
|
}
|
2018-09-25 00:20:49 -04:00
|
|
|
}
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2019-02-08 15:59:38 -05:00
|
|
|
|
2020-04-29 16:39:37 -04:00
|
|
|
unitTest({ perms: { read: false } }, async function readLinkPerm(): Promise<
|
2020-03-04 11:31:14 -05:00
|
|
|
void
|
|
|
|
> {
|
2020-06-24 18:57:08 -04:00
|
|
|
await assertThrowsAsync(async () => {
|
2020-04-29 16:39:37 -04:00
|
|
|
await Deno.readLink("/symlink");
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2019-02-08 15:59:38 -05:00
|
|
|
});
|