summaryrefslogtreecommitdiff
path: root/cli/tests/unit/fetch_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r--cli/tests/unit/fetch_test.ts58
1 files changed, 57 insertions, 1 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index bc61d67b5..98134728e 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -23,7 +23,7 @@ unitTest(
unitTest({ permissions: { net: true } }, async function fetchProtocolError() {
await assertRejects(
async () => {
- await fetch("file:///");
+ await fetch("ftp://localhost:21/a/file");
},
TypeError,
"not supported",
@@ -1360,3 +1360,59 @@ unitTest(
client.close();
},
);
+
+unitTest(async function fetchFilePerm() {
+ await assertRejects(async () => {
+ await fetch(new URL("../testdata/subdir/json_1.json", import.meta.url));
+ }, Deno.errors.PermissionDenied);
+});
+
+unitTest(async function fetchFilePermDoesNotExist() {
+ await assertRejects(async () => {
+ await fetch(new URL("./bad.json", import.meta.url));
+ }, Deno.errors.PermissionDenied);
+});
+
+unitTest(
+ { permissions: { read: true } },
+ async function fetchFileBadMethod() {
+ await assertRejects(
+ async () => {
+ await fetch(
+ new URL("../testdata/subdir/json_1.json", import.meta.url),
+ {
+ method: "POST",
+ },
+ );
+ },
+ TypeError,
+ "Fetching files only supports the GET method. Received POST.",
+ );
+ },
+);
+
+unitTest(
+ { permissions: { read: true } },
+ async function fetchFileDoesNotExist() {
+ await assertRejects(
+ async () => {
+ await fetch(new URL("./bad.json", import.meta.url));
+ },
+ TypeError,
+ );
+ },
+);
+
+unitTest(
+ { permissions: { read: true } },
+ async function fetchFile() {
+ const res = await fetch(
+ new URL("../testdata/subdir/json_1.json", import.meta.url),
+ );
+ assert(res.ok);
+ const fixture = await Deno.readTextFile(
+ "cli/tests/testdata/subdir/json_1.json",
+ );
+ assertEquals(await res.text(), fixture);
+ },
+);