mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
test(cli): use assertThrows and assertThrowsAsync for chown tests (#7106)
This commit is contained in:
parent
e8968e6bf4
commit
dcc7348090
1 changed files with 16 additions and 21 deletions
|
@ -1,5 +1,10 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { unitTest, assertEquals, assert } from "./test_util.ts";
|
import {
|
||||||
|
unitTest,
|
||||||
|
assertEquals,
|
||||||
|
assertThrows,
|
||||||
|
assertThrowsAsync,
|
||||||
|
} from "./test_util.ts";
|
||||||
|
|
||||||
// chown on Windows is noop for now, so ignore its testing on Windows
|
// chown on Windows is noop for now, so ignore its testing on Windows
|
||||||
|
|
||||||
|
@ -28,11 +33,9 @@ unitTest(
|
||||||
{ ignore: Deno.build.os == "windows" },
|
{ ignore: Deno.build.os == "windows" },
|
||||||
async function chownNoWritePermission(): Promise<void> {
|
async function chownNoWritePermission(): Promise<void> {
|
||||||
const filePath = "chown_test_file.txt";
|
const filePath = "chown_test_file.txt";
|
||||||
try {
|
await assertThrowsAsync(async () => {
|
||||||
await Deno.chown(filePath, 1000, 1000);
|
await Deno.chown(filePath, 1000, 1000);
|
||||||
} catch (e) {
|
}, Deno.errors.PermissionDenied);
|
||||||
assert(e instanceof Deno.errors.PermissionDenied);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -42,11 +45,9 @@ unitTest(
|
||||||
const { uid, gid } = await getUidAndGid();
|
const { uid, gid } = await getUidAndGid();
|
||||||
const filePath = Deno.makeTempDirSync() + "/chown_test_file.txt";
|
const filePath = Deno.makeTempDirSync() + "/chown_test_file.txt";
|
||||||
|
|
||||||
try {
|
assertThrows(() => {
|
||||||
Deno.chownSync(filePath, uid, gid);
|
Deno.chownSync(filePath, uid, gid);
|
||||||
} catch (e) {
|
}, Deno.errors.NotFound);
|
||||||
assert(e instanceof Deno.errors.NotFound);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -56,11 +57,9 @@ unitTest(
|
||||||
const { uid, gid } = await getUidAndGid();
|
const { uid, gid } = await getUidAndGid();
|
||||||
const filePath = (await Deno.makeTempDir()) + "/chown_test_file.txt";
|
const filePath = (await Deno.makeTempDir()) + "/chown_test_file.txt";
|
||||||
|
|
||||||
try {
|
await assertThrowsAsync(async () => {
|
||||||
await Deno.chown(filePath, uid, gid);
|
await Deno.chown(filePath, uid, gid);
|
||||||
} catch (e) {
|
}, Deno.errors.NotFound);
|
||||||
assert(e instanceof Deno.errors.NotFound);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -71,12 +70,10 @@ unitTest(
|
||||||
const filePath = dirPath + "/chown_test_file.txt";
|
const filePath = dirPath + "/chown_test_file.txt";
|
||||||
Deno.writeTextFileSync(filePath, "Hello");
|
Deno.writeTextFileSync(filePath, "Hello");
|
||||||
|
|
||||||
try {
|
assertThrows(() => {
|
||||||
// try changing the file's owner to root
|
// try changing the file's owner to root
|
||||||
Deno.chownSync(filePath, 0, 0);
|
Deno.chownSync(filePath, 0, 0);
|
||||||
} catch (e) {
|
}, Deno.errors.PermissionDenied);
|
||||||
assert(e instanceof Deno.errors.PermissionDenied);
|
|
||||||
}
|
|
||||||
Deno.removeSync(dirPath, { recursive: true });
|
Deno.removeSync(dirPath, { recursive: true });
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -88,12 +85,10 @@ unitTest(
|
||||||
const filePath = dirPath + "/chown_test_file.txt";
|
const filePath = dirPath + "/chown_test_file.txt";
|
||||||
await Deno.writeTextFile(filePath, "Hello");
|
await Deno.writeTextFile(filePath, "Hello");
|
||||||
|
|
||||||
try {
|
await assertThrowsAsync(async () => {
|
||||||
// try changing the file's owner to root
|
// try changing the file's owner to root
|
||||||
await Deno.chown(filePath, 0, 0);
|
await Deno.chown(filePath, 0, 0);
|
||||||
} catch (e) {
|
}, Deno.errors.PermissionDenied);
|
||||||
assert(e instanceof Deno.errors.PermissionDenied);
|
|
||||||
}
|
|
||||||
await Deno.remove(dirPath, { recursive: true });
|
await Deno.remove(dirPath, { recursive: true });
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue