summaryrefslogtreecommitdiff
path: root/cli/tests/unit/chown_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/chown_test.ts')
-rw-r--r--cli/tests/unit/chown_test.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/cli/tests/unit/chown_test.ts b/cli/tests/unit/chown_test.ts
index 724ea5a21..bcd5ab9fe 100644
--- a/cli/tests/unit/chown_test.ts
+++ b/cli/tests/unit/chown_test.ts
@@ -127,6 +127,26 @@ if (Deno.build.os !== "windows") {
unitTest(
{ perms: { run: true, write: true } },
+ async function chownSyncWithUrl(): Promise<void> {
+ // TODO: same as chownSyncSucceed
+ const { uid, gid } = await getUidAndGid();
+
+ const enc = new TextEncoder();
+ const dirPath = Deno.makeTempDirSync();
+ const fileUrl = new URL(`file://${dirPath}/chown_test_file.txt`);
+ const fileData = enc.encode("Hello");
+ Deno.writeFileSync(fileUrl, fileData);
+
+ // the test script creates this file with the same uid and gid,
+ // here chown is a noop so it succeeds under non-priviledged user
+ Deno.chownSync(fileUrl, uid, gid);
+
+ Deno.removeSync(dirPath, { recursive: true });
+ }
+ );
+
+ unitTest(
+ { perms: { run: true, write: true } },
async function chownSucceed(): Promise<void> {
// TODO: same as chownSyncSucceed
const { uid, gid } = await getUidAndGid();
@@ -144,4 +164,24 @@ if (Deno.build.os !== "windows") {
Deno.removeSync(dirPath, { recursive: true });
}
);
+
+ unitTest(
+ { perms: { run: true, write: true } },
+ async function chownWithUrl(): Promise<void> {
+ // TODO: same as chownSyncSucceed
+ const { uid, gid } = await getUidAndGid();
+
+ const enc = new TextEncoder();
+ const dirPath = await Deno.makeTempDir();
+ const fileUrl = new URL(`file://${dirPath}/chown_test_file.txt`);
+ const fileData = enc.encode("Hello");
+ await Deno.writeFile(fileUrl, fileData);
+
+ // the test script creates this file with the same uid and gid,
+ // here chown is a noop so it succeeds under non-priviledged user
+ await Deno.chown(fileUrl, uid, gid);
+
+ Deno.removeSync(dirPath, { recursive: true });
+ }
+ );
}