2020-09-21 08:26:41 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-15 11:48:46 -04:00
|
|
|
import { readlink, readlinkSync } from "./_fs_readlink.ts";
|
2020-09-27 06:22:32 -04:00
|
|
|
import { assert, assertEquals } from "../../testing/asserts.ts";
|
2020-05-22 13:37:25 -04:00
|
|
|
import * as path from "../path.ts";
|
2020-03-15 11:48:46 -04:00
|
|
|
|
|
|
|
const testDir = Deno.makeTempDirSync();
|
2020-05-22 13:37:25 -04:00
|
|
|
const oldname = path.join(testDir, "oldname");
|
|
|
|
const newname = path.join(testDir, "newname");
|
2020-03-15 11:48:46 -04:00
|
|
|
|
2020-05-22 13:37:25 -04:00
|
|
|
if (Deno.build.os === "windows") {
|
|
|
|
Deno.symlinkSync(oldname, newname, { type: "file" });
|
|
|
|
} else {
|
2020-03-15 11:48:46 -04:00
|
|
|
Deno.symlinkSync(oldname, newname);
|
|
|
|
}
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-15 11:48:46 -04:00
|
|
|
name: "readlinkSuccess",
|
|
|
|
async fn() {
|
|
|
|
const data = await new Promise((res, rej) => {
|
|
|
|
readlink(newname, (err, data) => {
|
|
|
|
if (err) {
|
|
|
|
rej(err);
|
|
|
|
}
|
|
|
|
res(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
assertEquals(typeof data, "string");
|
|
|
|
assertEquals(data as string, oldname);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-15 11:48:46 -04:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-15 11:48:46 -04:00
|
|
|
name: "readlinkEncodeBufferSuccess",
|
|
|
|
async fn() {
|
|
|
|
const data = await new Promise((res, rej) => {
|
|
|
|
readlink(newname, { encoding: "buffer" }, (err, data) => {
|
|
|
|
if (err) {
|
|
|
|
rej(err);
|
|
|
|
}
|
|
|
|
res(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
assert(data instanceof Uint8Array);
|
|
|
|
assertEquals(new TextDecoder().decode(data as Uint8Array), oldname);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-15 11:48:46 -04:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-15 11:48:46 -04:00
|
|
|
name: "readlinkSyncSuccess",
|
|
|
|
fn() {
|
|
|
|
const data = readlinkSync(newname);
|
|
|
|
assertEquals(typeof data, "string");
|
|
|
|
assertEquals(data as string, oldname);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-15 11:48:46 -04:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-15 11:48:46 -04:00
|
|
|
name: "readlinkEncodeBufferSuccess",
|
|
|
|
fn() {
|
|
|
|
const data = readlinkSync(newname, { encoding: "buffer" });
|
|
|
|
assert(data instanceof Uint8Array);
|
|
|
|
assertEquals(new TextDecoder().decode(data as Uint8Array), oldname);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-15 11:48:46 -04:00
|
|
|
});
|