diff options
Diffstat (limited to 'std/node')
-rw-r--r-- | std/node/_fs/_fs_chmod_test.ts | 85 | ||||
-rw-r--r-- | std/node/_fs/_fs_chown_test.ts | 86 | ||||
-rwxr-xr-x | std/node/fs_test.ts | 39 |
3 files changed, 117 insertions, 93 deletions
diff --git a/std/node/_fs/_fs_chmod_test.ts b/std/node/_fs/_fs_chmod_test.ts index 9be6669f2..42c29cdc8 100644 --- a/std/node/_fs/_fs_chmod_test.ts +++ b/std/node/_fs/_fs_chmod_test.ts @@ -3,47 +3,6 @@ const { test } = Deno; import { fail, assert } from "../../testing/asserts.ts"; import { chmod, chmodSync } from "./_fs_chmod.ts"; -if (Deno.build.os !== "win") { - test({ - name: "ASYNC: Permissions are changed (non-Windows)", - async fn() { - const tempFile: string = await Deno.makeTempFile(); - const originalFileMode: number | null = (await Deno.lstat(tempFile)).mode; - await new Promise((resolve, reject) => { - chmod(tempFile, 0o777, err => { - if (err) reject(err); - else resolve(); - }); - }) - .then(() => { - const newFileMode: number | null = Deno.lstatSync(tempFile).mode; - assert(newFileMode && originalFileMode); - assert(newFileMode === 33279 && newFileMode > originalFileMode); - }) - .catch(() => { - fail(); - }) - .finally(() => { - Deno.removeSync(tempFile); - }); - } - }); - - test({ - name: "SYNC: Permissions are changed (non-Windows)", - fn() { - const tempFile: string = Deno.makeTempFileSync(); - const originalFileMode: number | null = Deno.lstatSync(tempFile).mode; - chmodSync(tempFile, "777"); - - const newFileMode: number | null = Deno.lstatSync(tempFile).mode; - assert(newFileMode && originalFileMode); - assert(newFileMode === 33279 && newFileMode > originalFileMode); - Deno.removeSync(tempFile); - } - }); -} - test({ name: "ASYNC: Error passed in callback function when bad mode passed in", async fn() { @@ -61,6 +20,7 @@ test({ }); } }); + test({ name: "SYNC: Error thrown when bad mode passed in", fn() { @@ -73,3 +33,46 @@ test({ assert(caughtError); } }); + +const skip = Deno.build.os == "win"; + +test({ + skip, + name: "ASYNC: Permissions are changed (non-Windows)", + async fn() { + const tempFile: string = await Deno.makeTempFile(); + const originalFileMode: number | null = (await Deno.lstat(tempFile)).mode; + await new Promise((resolve, reject) => { + chmod(tempFile, 0o777, err => { + if (err) reject(err); + else resolve(); + }); + }) + .then(() => { + const newFileMode: number | null = Deno.lstatSync(tempFile).mode; + assert(newFileMode && originalFileMode); + assert(newFileMode === 33279 && newFileMode > originalFileMode); + }) + .catch(() => { + fail(); + }) + .finally(() => { + Deno.removeSync(tempFile); + }); + } +}); + +test({ + skip, + name: "SYNC: Permissions are changed (non-Windows)", + fn() { + const tempFile: string = Deno.makeTempFileSync(); + const originalFileMode: number | null = Deno.lstatSync(tempFile).mode; + chmodSync(tempFile, "777"); + + const newFileMode: number | null = Deno.lstatSync(tempFile).mode; + assert(newFileMode && originalFileMode); + assert(newFileMode === 33279 && newFileMode > originalFileMode); + Deno.removeSync(tempFile); + } +}); diff --git a/std/node/_fs/_fs_chown_test.ts b/std/node/_fs/_fs_chown_test.ts index 51a463d88..f7b4a8cec 100644 --- a/std/node/_fs/_fs_chown_test.ts +++ b/std/node/_fs/_fs_chown_test.ts @@ -3,48 +3,50 @@ const { test } = Deno; import { fail, assertEquals } from "../../testing/asserts.ts"; import { chown, chownSync } from "./_fs_chown.ts"; -if (Deno.build.os !== "win") { - //chown is difficult to test. Best we can do is set the existing user id/group id again - test({ - name: "ASYNC: setting existing uid/gid works as expected (non-Windows)", - async fn() { - const tempFile: string = await Deno.makeTempFile(); - const originalUserId: number | null = (await Deno.lstat(tempFile)).uid; - const originalGroupId: number | null = (await Deno.lstat(tempFile)).gid; - await new Promise((resolve, reject) => { - chown(tempFile, originalUserId!, originalGroupId!, err => { - if (err) reject(err); - else resolve(); - }); +//chown is difficult to test. Best we can do is set the existing user id/group id again +const skip = Deno.build.os == "win"; + +test({ + skip, + name: "ASYNC: setting existing uid/gid works as expected (non-Windows)", + async fn() { + const tempFile: string = await Deno.makeTempFile(); + const originalUserId: number | null = (await Deno.lstat(tempFile)).uid; + const originalGroupId: number | null = (await Deno.lstat(tempFile)).gid; + await new Promise((resolve, reject) => { + chown(tempFile, originalUserId!, originalGroupId!, err => { + if (err) reject(err); + else resolve(); + }); + }) + .then(() => { + const newUserId: number | null = Deno.lstatSync(tempFile).uid; + const newGroupId: number | null = Deno.lstatSync(tempFile).gid; + assertEquals(newUserId, originalUserId); + assertEquals(newGroupId, originalGroupId); + }) + .catch(() => { + fail(); }) - .then(() => { - const newUserId: number | null = Deno.lstatSync(tempFile).uid; - const newGroupId: number | null = Deno.lstatSync(tempFile).gid; - assertEquals(newUserId, originalUserId); - assertEquals(newGroupId, originalGroupId); - }) - .catch(() => { - fail(); - }) - .finally(() => { - Deno.removeSync(tempFile); - }); - } - }); + .finally(() => { + Deno.removeSync(tempFile); + }); + } +}); - test({ - name: "SYNC: setting existing uid/gid works as expected (non-Windows)", - fn() { - const tempFile: string = Deno.makeTempFileSync(); - const originalUserId: number | null = Deno.lstatSync(tempFile).uid; - const originalGroupId: number | null = Deno.lstatSync(tempFile).gid; - chownSync(tempFile, originalUserId!, originalGroupId!); +test({ + skip, + name: "SYNC: setting existing uid/gid works as expected (non-Windows)", + fn() { + const tempFile: string = Deno.makeTempFileSync(); + const originalUserId: number | null = Deno.lstatSync(tempFile).uid; + const originalGroupId: number | null = Deno.lstatSync(tempFile).gid; + chownSync(tempFile, originalUserId!, originalGroupId!); - const newUserId: number | null = Deno.lstatSync(tempFile).uid; - const newGroupId: number | null = Deno.lstatSync(tempFile).gid; - assertEquals(newUserId, originalUserId); - assertEquals(newGroupId, originalGroupId); - Deno.removeSync(tempFile); - } - }); -} + const newUserId: number | null = Deno.lstatSync(tempFile).uid; + const newGroupId: number | null = Deno.lstatSync(tempFile).gid; + assertEquals(newUserId, originalUserId); + assertEquals(newGroupId, originalGroupId); + Deno.removeSync(tempFile); + } +}); diff --git a/std/node/fs_test.ts b/std/node/fs_test.ts index 9753d9520..96d0f6597 100755 --- a/std/node/fs_test.ts +++ b/std/node/fs_test.ts @@ -50,9 +50,16 @@ test(function readFileEncodeUtf8Success() { }); // Just for now, until we implement symlink for Windows. -if (Deno.build.os !== "win") { +const skip = Deno.build.os == "win"; + +if (!skip) { Deno.symlinkSync(oldname, newname); - test(async function readlinkSuccess() { +} + +test({ + skip, + name: "readlinkSuccess", + async fn() { const data = await new Promise((res, rej) => { readlink(newname, (err, data) => { if (err) { @@ -64,9 +71,13 @@ if (Deno.build.os !== "win") { assertEquals(typeof data, "string"); assertEquals(data as string, oldname); - }); + } +}); - test(async function readlinkEncodeBufferSuccess() { +test({ + skip, + name: "readlinkEncodeBufferSuccess", + async fn() { const data = await new Promise((res, rej) => { readlink(newname, { encoding: "buffer" }, (err, data) => { if (err) { @@ -78,17 +89,25 @@ if (Deno.build.os !== "win") { assert(data instanceof Uint8Array); assertEquals(new TextDecoder().decode(data as Uint8Array), oldname); - }); + } +}); - test(function readlinkSyncSuccess() { +test({ + skip, + name: "readlinkSyncSuccess", + fn() { const data = readlinkSync(newname); assertEquals(typeof data, "string"); assertEquals(data as string, oldname); - }); + } +}); - test(function readlinkEncodeBufferSuccess() { +test({ + skip, + name: "readlinkEncodeBufferSuccess", + fn() { const data = readlinkSync(newname, { encoding: "buffer" }); assert(data instanceof Uint8Array); assertEquals(new TextDecoder().decode(data as Uint8Array), oldname); - }); -} + } +}); |