aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/fetch.test.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-01-12 19:10:41 -0800
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-01-12 19:10:41 -0800
commit766f8ceebc76dd749ba5c104f802c7ebda289db9 (patch)
treef84ee560938188261f7f5604a65b83aae354a646 /test/bun.js/fetch.test.js
parentc03f7c998dd22689412658177e3a5736ce6b9034 (diff)
parent32f8cb31be6fb5b0b9aea1c6d4e95d118e8ef816 (diff)
downloadbun-766f8ceebc76dd749ba5c104f802c7ebda289db9.tar.gz
bun-766f8ceebc76dd749ba5c104f802c7ebda289db9.tar.zst
bun-766f8ceebc76dd749ba5c104f802c7ebda289db9.zip
Merge branch 'main' into dylan/github-dependencies
Diffstat (limited to 'test/bun.js/fetch.test.js')
-rw-r--r--test/bun.js/fetch.test.js44
1 files changed, 42 insertions, 2 deletions
diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js
index ca8e387bf..5d0ca4854 100644
--- a/test/bun.js/fetch.test.js
+++ b/test/bun.js/fetch.test.js
@@ -1,5 +1,5 @@
-import { it, describe, expect } from "bun:test";
-import fs, { unlinkSync } from "fs";
+import { afterAll, beforeAll, describe, expect, it, test } from "bun:test";
+import fs, { chmodSync, unlinkSync } from "fs";
import { mkfifo } from "mkfifo";
import { gc, withoutAggressiveGC } from "./gc";
@@ -393,6 +393,46 @@ describe("Bun.file", () => {
const { size } = Bun.file("/tmp/test-fifo");
expect(size).toBe(Infinity);
});
+
+ function forEachMethod(fn) {
+ const method = ["arrayBuffer", "text", "json"];
+ for (const m of method) {
+ test(m, fn(m));
+ }
+ }
+
+ describe("bad permissions throws", () => {
+ beforeAll(async () => {
+ try {
+ unlinkSync("/tmp/my-new-file");
+ } catch {}
+ await Bun.write("/tmp/my-new-file", "hey");
+ chmodSync("/tmp/my-new-file", 0o000);
+ });
+ afterAll(() => {
+ try {
+ unlinkSync("/tmp/my-new-file");
+ } catch {}
+ });
+
+ forEachMethod((m) => () => {
+ const file = Bun.file("/tmp/my-new-file");
+ expect(async () => await file[m]()).toThrow("Permission denied");
+ });
+ });
+
+ describe("non-existent file throws", () => {
+ beforeAll(() => {
+ try {
+ unlinkSync("/tmp/does-not-exist");
+ } catch {}
+ });
+
+ forEachMethod((m) => async () => {
+ const file = Bun.file("/tmp/does-not-exist");
+ expect(async () => await file[m]()).toThrow("No such file or directory");
+ });
+ });
});
describe("Blob", () => {