summaryrefslogtreecommitdiff
path: root/std/http/file_server_test.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2020-03-21 22:53:47 +0900
committerGitHub <noreply@github.com>2020-03-21 09:53:47 -0400
commit60cee4f045778777a16b6fffd6d5b9a1400d7246 (patch)
treea477bd147fbd548d478a289af5bd0681b1a34c4e /std/http/file_server_test.ts
parent0adc86f105204b2475126c36dfc10e678f67df56 (diff)
avoid using same port number for test (#4147)
Diffstat (limited to 'std/http/file_server_test.ts')
-rw-r--r--std/http/file_server_test.ts28
1 files changed, 20 insertions, 8 deletions
diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts
index 1fbe3ba97..b7cd8a7e1 100644
--- a/std/http/file_server_test.ts
+++ b/std/http/file_server_test.ts
@@ -2,9 +2,11 @@
import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts";
import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
+import { randomPort } from "./test_util.ts";
const { test } = Deno;
let fileServer: Deno.Process;
+const port = randomPort();
async function startFileServer(): Promise<void> {
fileServer = Deno.run({
args: [
@@ -14,7 +16,9 @@ async function startFileServer(): Promise<void> {
"--allow-net",
"http/file_server.ts",
".",
- "--cors"
+ "--cors",
+ "--port",
+ `${port}`
],
stdout: "piped",
stderr: "null"
@@ -34,7 +38,7 @@ function killFileServer(): void {
test(async function serveFile(): Promise<void> {
await startFileServer();
try {
- const res = await fetch("http://localhost:4500/README.md");
+ const res = await fetch(`http://localhost:${port}/README.md`);
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
assert(res.headers.has("content-type"));
@@ -52,7 +56,7 @@ test(async function serveFile(): Promise<void> {
test(async function serveDirectory(): Promise<void> {
await startFileServer();
try {
- const res = await fetch("http://localhost:4500/");
+ const res = await fetch(`http://localhost:${port}/`);
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
const page = await res.text();
@@ -74,7 +78,7 @@ test(async function serveDirectory(): Promise<void> {
test(async function serveFallback(): Promise<void> {
await startFileServer();
try {
- const res = await fetch("http://localhost:4500/badfile.txt");
+ const res = await fetch(`http://localhost:${port}/badfile.txt`);
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
assertEquals(res.status, 404);
@@ -87,12 +91,12 @@ test(async function serveFallback(): Promise<void> {
test(async function serveWithUnorthodoxFilename(): Promise<void> {
await startFileServer();
try {
- let res = await fetch("http://localhost:4500/http/testdata/%");
+ let res = await fetch(`http://localhost:${port}/http/testdata/%`);
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
assertEquals(res.status, 200);
res.body.close();
- res = await fetch("http://localhost:4500/http/testdata/test%20file.txt");
+ res = await fetch(`http://localhost:${port}/http/testdata/test%20file.txt`);
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
assertEquals(res.status, 200);
@@ -103,8 +107,16 @@ test(async function serveWithUnorthodoxFilename(): Promise<void> {
});
test(async function servePermissionDenied(): Promise<void> {
+ const _port = randomPort();
const deniedServer = Deno.run({
- args: [Deno.execPath(), "run", "--allow-net", "http/file_server.ts"],
+ args: [
+ Deno.execPath(),
+ "run",
+ "--allow-net",
+ "http/file_server.ts",
+ "-p",
+ `${_port}`
+ ],
stdout: "piped",
stderr: "piped"
});
@@ -116,7 +128,7 @@ test(async function servePermissionDenied(): Promise<void> {
assert(s !== Deno.EOF && s.includes("server listening"));
try {
- const res = await fetch("http://localhost:4500/");
+ const res = await fetch(`http://localhost:${_port}/`);
res.body.close();
assertStrContains(
(await errReader.readLine()) as string,