Skip to content

Commit 8f9a48f

Browse files
authored
chore(http): rename test file (denoland#3882)
1 parent ede6b79 commit 8f9a48f

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

http/file_server_test.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const serveDirOptions: ServeDirOptions = {
3131
enableCors: true,
3232
};
3333

34-
const TEST_FILE_PATH = join(testdataDir, "test file.txt");
34+
const TEST_FILE_PATH = join(testdataDir, "test_file.txt");
3535
const TEST_FILE_STAT = await Deno.stat(TEST_FILE_PATH);
3636
const TEST_FILE_SIZE = TEST_FILE_STAT.size;
3737
const TEST_FILE_ETAG = await calculate(TEST_FILE_STAT) as string;
@@ -98,7 +98,7 @@ async function fetchExactPath(
9898
}
9999

100100
Deno.test("serveDir() sets last-modified header", async () => {
101-
const req = new Request("http://localhost/test%20file.txt");
101+
const req = new Request("http://localhost/test_file.txt");
102102
const res = await serveDir(req, serveDirOptions);
103103
await res.body?.cancel();
104104
const lastModifiedHeader = res.headers.get("last-modified") as string;
@@ -111,7 +111,7 @@ Deno.test("serveDir() sets last-modified header", async () => {
111111
});
112112

113113
Deno.test("serveDir() sets date header", async () => {
114-
const req = new Request("http://localhost/test%20file.txt");
114+
const req = new Request("http://localhost/test_file.txt");
115115
const res = await serveDir(req, serveDirOptions);
116116
await res.body?.cancel();
117117
const dateHeader = res.headers.get("date") as string;
@@ -183,9 +183,9 @@ Deno.test("serveDir() returns a response even if fileinfo is inaccessible", asyn
183183
// Mock Deno.stat to test that the dirlisting page can be generated
184184
// even if the fileInfo for a particular file cannot be obtained.
185185

186-
// Assuming that fileInfo of `test file.txt` cannot be accessible
186+
// Assuming that fileInfo of `test_file.txt` cannot be accessible
187187
const denoStatStub = stub(Deno, "stat", (path): Promise<Deno.FileInfo> => {
188-
if (path.toString().includes("test file.txt")) {
188+
if (path.toString().includes("test_file.txt")) {
189189
return Promise.reject(new Error("__stubed_error__"));
190190
}
191191
return denoStatStub.original.call(Deno, path);
@@ -196,7 +196,7 @@ Deno.test("serveDir() returns a response even if fileinfo is inaccessible", asyn
196196
denoStatStub.restore();
197197

198198
assertEquals(res.status, 200);
199-
assertStringIncludes(page, "/test%20file.txt");
199+
assertStringIncludes(page, "/test_file.txt");
200200
});
201201

202202
Deno.test("serveDir() handles not found files", async () => {
@@ -267,7 +267,7 @@ Deno.test("serveDir() serves unusual filename", async () => {
267267
assert(res1.headers.has("access-control-allow-origin"));
268268
assert(res1.headers.has("access-control-allow-headers"));
269269

270-
const req2 = new Request("http://localhost/test%20file.txt");
270+
const req2 = new Request("http://localhost/test_file.txt");
271271
const res2 = await serveDir(req2, serveDirOptions);
272272
await res2.body?.cancel();
273273

@@ -413,7 +413,7 @@ Deno.test("serveDir() shows .. if it makes sense", async () => {
413413
});
414414

415415
Deno.test("serveDir() handles range request (bytes=0-0)", async () => {
416-
const req = new Request("http://localhost/test%20file.txt", {
416+
const req = new Request("http://localhost/test_file.txt", {
417417
headers: { range: "bytes=0-0" },
418418
});
419419
const res = await serveDir(req, serveDirOptions);
@@ -423,7 +423,7 @@ Deno.test("serveDir() handles range request (bytes=0-0)", async () => {
423423
});
424424

425425
Deno.test("serveDir() handles range request (bytes=0-100)", async () => {
426-
const req = new Request("http://localhost/test%20file.txt", {
426+
const req = new Request("http://localhost/test_file.txt", {
427427
headers: { range: "bytes=0-100" },
428428
});
429429
const res = await serveDir(req, serveDirOptions);
@@ -437,7 +437,7 @@ Deno.test("serveDir() handles range request (bytes=0-100)", async () => {
437437
});
438438

439439
Deno.test("serveDir() handles range request (bytes=300-)", async () => {
440-
const req = new Request("http://localhost/test%20file.txt", {
440+
const req = new Request("http://localhost/test_file.txt", {
441441
headers: { range: "bytes=300-" },
442442
});
443443
const res = await serveDir(req, serveDirOptions);
@@ -451,7 +451,7 @@ Deno.test("serveDir() handles range request (bytes=300-)", async () => {
451451
});
452452

453453
Deno.test("serveDir() handles range request (bytes=-200)", async () => {
454-
const req = new Request("http://localhost/test%20file.txt", {
454+
const req = new Request("http://localhost/test_file.txt", {
455455
headers: { range: "bytes=-200" },
456456
});
457457
const res = await serveDir(req, serveDirOptions);
@@ -466,7 +466,7 @@ Deno.test("serveDir() handles range request (bytes=-200)", async () => {
466466
});
467467

468468
Deno.test("serveDir() clamps ranges that are too large (bytes=0-999999999)", async () => {
469-
const req = new Request("http://localhost/test%20file.txt", {
469+
const req = new Request("http://localhost/test_file.txt", {
470470
headers: { range: "bytes=0-999999999" },
471471
});
472472
const res = await serveDir(req, serveDirOptions);
@@ -481,7 +481,7 @@ Deno.test("serveDir() clamps ranges that are too large (bytes=0-999999999)", asy
481481
});
482482

483483
Deno.test("serveDir() clamps ranges that are too large (bytes=-999999999)", async () => {
484-
const req = new Request("http://localhost/test%20file.txt", {
484+
const req = new Request("http://localhost/test_file.txt", {
485485
// This means the last 999999999 bytes. It is too big and should be clamped.
486486
headers: { range: "bytes=-999999999" },
487487
});
@@ -497,7 +497,7 @@ Deno.test("serveDir() clamps ranges that are too large (bytes=-999999999)", asyn
497497
});
498498

499499
Deno.test("serveDir() handles bad range request (bytes=500-200)", async () => {
500-
const req = new Request("http://localhost/test%20file.txt", {
500+
const req = new Request("http://localhost/test_file.txt", {
501501
headers: { range: "bytes=500-200" },
502502
});
503503
const res = await serveDir(req, serveDirOptions);
@@ -509,7 +509,7 @@ Deno.test("serveDir() handles bad range request (bytes=500-200)", async () => {
509509
});
510510

511511
Deno.test("serveDir() handles bad range request (bytes=99999-999999)", async () => {
512-
const req = new Request("http://localhost/test%20file.txt", {
512+
const req = new Request("http://localhost/test_file.txt", {
513513
headers: { range: "bytes=99999-999999" },
514514
});
515515
const res = await serveDir(req, serveDirOptions);
@@ -521,7 +521,7 @@ Deno.test("serveDir() handles bad range request (bytes=99999-999999)", async ()
521521
});
522522

523523
Deno.test("serveDir() handles bad range request (bytes=99999)", async () => {
524-
const req = new Request("http://localhost/test%20file.txt", {
524+
const req = new Request("http://localhost/test_file.txt", {
525525
headers: { range: "bytes=99999-" },
526526
});
527527
const res = await serveDir(req, serveDirOptions);
@@ -533,7 +533,7 @@ Deno.test("serveDir() handles bad range request (bytes=99999)", async () => {
533533
});
534534

535535
Deno.test("serveDir() ignores bad range request (bytes=100)", async () => {
536-
const req = new Request("http://localhost/test%20file.txt", {
536+
const req = new Request("http://localhost/test_file.txt", {
537537
headers: { range: "bytes=100" },
538538
});
539539
const res = await serveDir(req, serveDirOptions);
@@ -545,7 +545,7 @@ Deno.test("serveDir() ignores bad range request (bytes=100)", async () => {
545545
});
546546

547547
Deno.test("serveDir() ignores bad range request (bytes=a-b)", async () => {
548-
const req = new Request("http://localhost/test%20file.txt", {
548+
const req = new Request("http://localhost/test_file.txt", {
549549
headers: { range: "bytes=a-b" },
550550
});
551551
const res = await serveDir(req, serveDirOptions);
@@ -557,7 +557,7 @@ Deno.test("serveDir() ignores bad range request (bytes=a-b)", async () => {
557557
});
558558

559559
Deno.test("serveDir() ignores bad multi-range request (bytes=0-10, 20-30)", async () => {
560-
const req = new Request("http://localhost/test%20file.txt", {
560+
const req = new Request("http://localhost/test_file.txt", {
561561
headers: { range: "bytes=0-10, 20-30" },
562562
});
563563
const res = await serveDir(req, serveDirOptions);
@@ -589,15 +589,15 @@ Deno.test("serveDir() sets accept-ranges header to bytes for directory listing",
589589
});
590590

591591
Deno.test("serveDir() sets accept-ranges header to bytes for file response", async () => {
592-
const req = new Request("http://localhost/test%20file.txt");
592+
const req = new Request("http://localhost/test_file.txt");
593593
const res = await serveDir(req, serveDirOptions);
594594
await res.body?.cancel();
595595

596596
assertEquals(res.headers.get("accept-ranges"), "bytes");
597597
});
598598

599599
Deno.test("serveDir() sets headers if provided as arguments", async () => {
600-
const req = new Request("http://localhost/test%20file.txt");
600+
const req = new Request("http://localhost/test_file.txt");
601601
const res = await serveDir(req, {
602602
...serveDirOptions,
603603
headers: ["cache-control:max-age=100", "x-custom-header:hi"],
@@ -609,15 +609,15 @@ Deno.test("serveDir() sets headers if provided as arguments", async () => {
609609
});
610610

611611
Deno.test("serveDir() sets etag header", async () => {
612-
const req = new Request("http://localhost/test%20file.txt");
612+
const req = new Request("http://localhost/test_file.txt");
613613
const res = await serveDir(req, serveDirOptions);
614614
await res.body?.cancel();
615615

616616
assertEquals(res.headers.get("etag"), TEST_FILE_ETAG);
617617
});
618618

619619
Deno.test("serveDir() serves empty HTTP 304 response for if-none-match request of unmodified file", async () => {
620-
const req = new Request("http://localhost/test%20file.txt", {
620+
const req = new Request("http://localhost/test_file.txt", {
621621
headers: { "if-none-match": TEST_FILE_ETAG },
622622
});
623623
const res = await serveDir(req, serveDirOptions);
@@ -628,7 +628,7 @@ Deno.test("serveDir() serves empty HTTP 304 response for if-none-match request o
628628
});
629629

630630
Deno.test("serveDir() serves HTTP 304 response for if-modified-since request of unmodified file", async () => {
631-
const req = new Request("http://localhost/test%20file.txt", {
631+
const req = new Request("http://localhost/test_file.txt", {
632632
headers: { "if-modified-since": TEST_FILE_LAST_MODIFIED },
633633
});
634634
const res = await serveDir(req, serveDirOptions);
@@ -648,7 +648,7 @@ Deno.test("serveDir() serves HTTP 304 response for if-modified-since request of
648648
Deno.test(
649649
"serveDir() only uses if-none-match header if if-non-match and if-modified-since headers are provided",
650650
async () => {
651-
const req = new Request("http://localhost/test%20file.txt", {
651+
const req = new Request("http://localhost/test_file.txt", {
652652
headers: {
653653
"if-none-match": "not match etag",
654654
"if-modified-since": TEST_FILE_LAST_MODIFIED,
@@ -663,7 +663,7 @@ Deno.test(
663663
);
664664

665665
Deno.test("serveFile() serves test file", async () => {
666-
const req = new Request("http://localhost/testdata/test file.txt");
666+
const req = new Request("http://localhost/testdata/test_file.txt");
667667
const res = await serveFile(req, TEST_FILE_PATH);
668668

669669
assertEquals(res.status, 200);
@@ -690,7 +690,7 @@ Deno.test("serveFile() serves HTTP 404 when the path is a directory", async () =
690690
});
691691

692692
Deno.test("serveFile() handles bad range request (bytes=200-500)", async () => {
693-
const req = new Request("http://localhost/testdata/test file.txt", {
693+
const req = new Request("http://localhost/testdata/test_file.txt", {
694694
headers: { range: "bytes=200-500" },
695695
});
696696
const res = await serveFile(req, TEST_FILE_PATH);
@@ -700,7 +700,7 @@ Deno.test("serveFile() handles bad range request (bytes=200-500)", async () => {
700700
});
701701

702702
Deno.test("serveFile() handles bad range request (bytes=500-200)", async () => {
703-
const req = new Request("http://localhost/testdata/test file.txt", {
703+
const req = new Request("http://localhost/testdata/test_file.txt", {
704704
headers: { range: "bytes=500-200" },
705705
});
706706
const res = await serveFile(req, TEST_FILE_PATH);
@@ -710,7 +710,7 @@ Deno.test("serveFile() handles bad range request (bytes=500-200)", async () => {
710710
});
711711

712712
Deno.test("serveFile() serves HTTP 304 response for if-modified-since request of unmodified file", async () => {
713-
const req = new Request("http://localhost/testdata/test file.txt", {
713+
const req = new Request("http://localhost/testdata/test_file.txt", {
714714
headers: { "if-none-match": TEST_FILE_ETAG },
715715
});
716716
const res = await serveFile(req, TEST_FILE_PATH);
@@ -727,7 +727,7 @@ Deno.test("serveFile() serves HTTP 304 response for if-modified-since request of
727727
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since}
728728
*/
729729
Deno.test("serveFile() only uses if-none-match header if if-non-match and if-modified-since headers are provided", async () => {
730-
const req = new Request("http://localhost/testdata/test file.txt", {
730+
const req = new Request("http://localhost/testdata/test_file.txt", {
731731
headers: {
732732
"if-none-match": "not match etag",
733733
"if-modified-since": TEST_FILE_LAST_MODIFIED,
@@ -750,10 +750,10 @@ Deno.test("serveFile() etag value falls back to DENO_DEPLOYMENT_ID if fileInfo.m
750750
import { serveFile } from "${import.meta.resolve("./file_server.ts")}";
751751
import { fromFileUrl } from "${import.meta.resolve("../path/mod.ts")}";
752752
import { assertEquals } from "${import.meta.resolve("../assert/assert_equals.ts")}";
753-
const testdataPath = "${toFileUrl(join(testdataDir, "test file.txt"))}";
753+
const testdataPath = "${toFileUrl(join(testdataDir, "test_file.txt"))}";
754754
const fileInfo = await Deno.stat(new URL(testdataPath));
755755
fileInfo.mtime = null;
756-
const req = new Request("http://localhost/testdata/test file.txt");
756+
const req = new Request("http://localhost/testdata/test_file.txt");
757757
const res = await serveFile(req, fromFileUrl(testdataPath), { fileInfo });
758758
assertEquals(res.headers.get("etag"), \`${hashedDenoDeploymentId}\`);
759759
`;
@@ -840,24 +840,24 @@ Deno.test("serveDir() redirects a directory URL not ending with a slash correctl
840840
});
841841

842842
Deno.test("serveDir() redirects a file URL ending with a slash correctly even with a query string", async () => {
843-
const url = "http://localhost/http/testdata/test%20file.txt/?test";
843+
const url = "http://localhost/http/testdata/test_file.txt/?test";
844844
const res = await serveDir(new Request(url), { showIndex: true });
845845

846846
assertEquals(res.status, 301);
847847
assertEquals(
848848
res.headers.get("Location"),
849-
"http://localhost/http/testdata/test%20file.txt?test",
849+
"http://localhost/http/testdata/test_file.txt?test",
850850
);
851851
});
852852

853853
Deno.test("serveDir() redirects non-canonical URLs", async () => {
854-
const url = "http://localhost/http/testdata//////test%20file.txt/////?test";
854+
const url = "http://localhost/http/testdata//////test_file.txt/////?test";
855855
const res = await serveDir(new Request(url), { showIndex: true });
856856

857857
assertEquals(res.status, 301);
858858
assertEquals(
859859
res.headers.get("Location"),
860-
"http://localhost/http/testdata/test%20file.txt/?test",
860+
"http://localhost/http/testdata/test_file.txt/?test",
861861
);
862862
});
863863

0 commit comments

Comments
 (0)