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 {
|
|
|
|
assertEquals,
|
|
|
|
assertThrows,
|
|
|
|
assertThrowsAsync,
|
2020-11-23 16:11:56 -05:00
|
|
|
pathToAbsoluteFileUrl,
|
2020-09-27 06:22:32 -04:00
|
|
|
unitTest,
|
2020-06-24 18:57:08 -04:00
|
|
|
} 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();
|
2020-07-14 15:24:17 -04:00
|
|
|
const target = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\target" : "/target");
|
|
|
|
const symlink = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\symlink" : "/symlink");
|
2020-03-04 11:31:14 -05:00
|
|
|
Deno.mkdirSync(target);
|
2020-06-25 07:27:23 -04:00
|
|
|
Deno.symlinkSync(target, symlink);
|
|
|
|
const targetPath = Deno.readLinkSync(symlink);
|
|
|
|
assertEquals(targetPath, target);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2018-09-25 00:20:49 -04:00
|
|
|
|
2020-11-23 16:11:56 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
|
|
|
function readLinkSyncUrlSuccess(): void {
|
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const target = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\target" : "/target");
|
|
|
|
const symlink = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\symlink" : "/symlink");
|
|
|
|
Deno.mkdirSync(target);
|
|
|
|
Deno.symlinkSync(target, symlink);
|
|
|
|
const targetPath = Deno.readLinkSync(pathToAbsoluteFileUrl(symlink));
|
|
|
|
assertEquals(targetPath, target);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
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();
|
2020-07-14 15:24:17 -04:00
|
|
|
const target = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\target" : "/target");
|
|
|
|
const symlink = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\symlink" : "/symlink");
|
2020-03-04 11:31:14 -05:00
|
|
|
Deno.mkdirSync(target);
|
2020-06-25 07:27:23 -04:00
|
|
|
Deno.symlinkSync(target, symlink);
|
|
|
|
const targetPath = await Deno.readLink(symlink);
|
|
|
|
assertEquals(targetPath, target);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2019-02-08 15:59:38 -05:00
|
|
|
|
2020-11-23 16:11:56 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
|
|
|
async function readLinkUrlSuccess(): Promise<void> {
|
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const target = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\target" : "/target");
|
|
|
|
const symlink = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\symlink" : "/symlink");
|
|
|
|
Deno.mkdirSync(target);
|
|
|
|
Deno.symlinkSync(target, symlink);
|
|
|
|
const targetPath = await Deno.readLink(pathToAbsoluteFileUrl(symlink));
|
|
|
|
assertEquals(targetPath, target);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
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
|
|
|
});
|