diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-07-04 13:05:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-04 13:05:01 -0400 |
commit | 5f9e600c5bb78ae35a9a12d250f1d7cad79cf7a4 (patch) | |
tree | df0085e1287912f014bf804d2070f189a367b772 /cli | |
parent | fca492907cb0e6b12f202681ccf36278b5bfa81a (diff) |
chore: port http_server.py to rust (#6364)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/http_util.rs | 14 | ||||
-rw-r--r-- | cli/tests/053_import_compression/brotli.header | 3 | ||||
-rw-r--r-- | cli/tests/053_import_compression/gziped.header | 3 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 3 | ||||
-rw-r--r-- | cli/tests/unit/README.md | 6 | ||||
-rw-r--r-- | cli/tests/unit/body_test.ts | 2 | ||||
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 50 | ||||
-rw-r--r-- | cli/tests/x_deno_warning.js.header | 2 |
8 files changed, 34 insertions, 49 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs index 5b434a276..f0109ca36 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -249,7 +249,7 @@ mod tests { #[tokio::test] async fn test_fetch_string() { let http_server_guard = test_util::http_server(); - // Relies on external http server. See tools/http_server.py + // Relies on external http server. See target/debug/test_server let url = Url::parse("http://127.0.0.1:4545/cli/tests/fixture.json").unwrap(); let client = create_http_client(None).unwrap(); @@ -268,7 +268,7 @@ mod tests { #[tokio::test] async fn test_fetch_gzip() { let http_server_guard = test_util::http_server(); - // Relies on external http server. See tools/http_server.py + // Relies on external http server. See target/debug/test_server let url = Url::parse( "http://127.0.0.1:4545/cli/tests/053_import_compression/gziped", ) @@ -317,7 +317,7 @@ mod tests { #[tokio::test] async fn test_fetch_brotli() { let http_server_guard = test_util::http_server(); - // Relies on external http server. See tools/http_server.py + // Relies on external http server. See target/debug/test_server let url = Url::parse( "http://127.0.0.1:4545/cli/tests/053_import_compression/brotli", ) @@ -342,7 +342,7 @@ mod tests { #[tokio::test] async fn test_fetch_once_with_redirect() { let http_server_guard = test_util::http_server(); - // Relies on external http server. See tools/http_server.py + // Relies on external http server. See target/debug/test_server let url = Url::parse("http://127.0.0.1:4546/cli/tests/fixture.json").unwrap(); // Dns resolver substitutes `127.0.0.1` with `localhost` @@ -399,7 +399,7 @@ mod tests { #[tokio::test] async fn test_fetch_with_cafile_string() { let http_server_guard = test_util::http_server(); - // Relies on external http server. See tools/http_server.py + // Relies on external http server. See target/debug/test_server let url = Url::parse("https://localhost:5545/cli/tests/fixture.json").unwrap(); @@ -425,7 +425,7 @@ mod tests { #[tokio::test] async fn test_fetch_with_cafile_gzip() { let http_server_guard = test_util::http_server(); - // Relies on external http server. See tools/http_server.py + // Relies on external http server. See target/debug/test_server let url = Url::parse( "https://localhost:5545/cli/tests/053_import_compression/gziped", ) @@ -487,7 +487,7 @@ mod tests { #[tokio::test] async fn test_fetch_with_cafile_brotli() { let http_server_guard = test_util::http_server(); - // Relies on external http server. See tools/http_server.py + // Relies on external http server. See target/debug/test_server let url = Url::parse( "https://localhost:5545/cli/tests/053_import_compression/brotli", ) diff --git a/cli/tests/053_import_compression/brotli.header b/cli/tests/053_import_compression/brotli.header deleted file mode 100644 index 6047a3993..000000000 --- a/cli/tests/053_import_compression/brotli.header +++ /dev/null @@ -1,3 +0,0 @@ -Content-Encoding: br -Content-Type: application/javascript -Content-Length: 26
\ No newline at end of file diff --git a/cli/tests/053_import_compression/gziped.header b/cli/tests/053_import_compression/gziped.header deleted file mode 100644 index fda818af6..000000000 --- a/cli/tests/053_import_compression/gziped.header +++ /dev/null @@ -1,3 +0,0 @@ -Content-Encoding: gzip -Content-Type: application/javascript -Content-Length: 39
\ No newline at end of file diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 6855df707..616849520 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2600,7 +2600,8 @@ fn test_permissions_net_listen_allow_localhost_4555_fail() { #[test] fn test_permissions_net_listen_allow_localhost() { - // Port 4600 is chosen to not colide with those used by tools/http_server.py + // Port 4600 is chosen to not colide with those used by + // target/debug/test_server let (_, err) = util::run_and_collect_output( true, "run --allow-net=localhost complex_permissions_test.ts netListen localhost:4600", diff --git a/cli/tests/unit/README.md b/cli/tests/unit/README.md index c333b0046..1546038c4 100644 --- a/cli/tests/unit/README.md +++ b/cli/tests/unit/README.md @@ -75,6 +75,6 @@ RUST_BACKTRACE=1 cargo run -- run --unstable --allow-read --allow-write cli/test ### Http server -`tools/http_server.py` is required to run when one's running unit tests. During -CI it's spawned automatically, but if you want to run tests manually make sure -that server is spawned otherwise there'll be cascade of test failures. +`target/debug/test_server` is required to run when one's running unit tests. +During CI it's spawned automatically, but if you want to run tests manually make +sure that server is spawned otherwise there'll be cascade of test failures. diff --git a/cli/tests/unit/body_test.ts b/cli/tests/unit/body_test.ts index d0423f7de..3b01190a6 100644 --- a/cli/tests/unit/body_test.ts +++ b/cli/tests/unit/body_test.ts @@ -36,7 +36,7 @@ unitTest( { perms: { net: true } }, async function bodyMultipartFormData(): Promise<void> { const response = await fetch( - "http://localhost:4545/cli/tests/subdir/multipart_form_data.txt" + "http://localhost:4545/multipart_form_data.txt" ); const text = await response.text(); diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index a52a7809a..1dab8f7f9 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -67,7 +67,6 @@ unitTest({ perms: { net: true } }, async function fetchHeaders(): Promise< const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const headers = response.headers; assertEquals(headers.get("Content-Type"), "application/json"); - assert(headers.get("Server")!.startsWith("SimpleHTTP")); const _json = await response.json(); }); @@ -162,13 +161,10 @@ unitTest( { perms: { net: true } }, async function fetchBodyReaderBigBody(): Promise<void> { const data = "a".repeat(10 << 10); // 10mb - const response = await fetch( - "http://localhost:4545/cli/tests/echo_server", - { - method: "POST", - body: data, - } - ); + const response = await fetch("http://localhost:4545/echo_server", { + method: "POST", + body: data, + }); assert(response.body !== null); const reader = await response.body.getReader(); let total = 0; @@ -210,7 +206,7 @@ unitTest( { perms: { net: true } }, async function fetchMultipartFormDataSuccess(): Promise<void> { const response = await fetch( - "http://localhost:4545/cli/tests/subdir/multipart_form_data.txt" + "http://localhost:4545/multipart_form_data.txt" ); const formData = await response.formData(); assert(formData.has("field_1")); @@ -315,12 +311,12 @@ unitTest( perms: { net: true }, }, async function fetchWithRedirection(): Promise<void> { - const response = await fetch("http://localhost:4546/"); // will redirect to http://localhost:4545/ + const response = await fetch("http://localhost:4546/README.md"); assertEquals(response.status, 200); assertEquals(response.statusText, "OK"); - assertEquals(response.url, "http://localhost:4545/"); + assertEquals(response.url, "http://localhost:4545/README.md"); const body = await response.text(); - assert(body.includes("<title>Directory listing for /</title>")); + assert(body.includes("Deno")); } ); @@ -329,11 +325,13 @@ unitTest( perms: { net: true }, }, async function fetchWithRelativeRedirection(): Promise<void> { - const response = await fetch("http://localhost:4545/cli/tests"); // will redirect to /cli/tests/ + const response = await fetch( + "http://localhost:4545/cli/tests/001_hello.js" + ); assertEquals(response.status, 200); assertEquals(response.statusText, "OK"); const body = await response.text(); - assert(body.includes("<title>Directory listing for /cli/tests/</title>")); + assert(body.includes("Hello")); } ); @@ -769,13 +767,10 @@ unitTest( { perms: { net: true } }, async function fetchBodyReaderWithCancelAndNewReader(): Promise<void> { const data = "a".repeat(1 << 10); - const response = await fetch( - "http://localhost:4545/cli/tests/echo_server", - { - method: "POST", - body: data, - } - ); + const response = await fetch("http://localhost:4545/echo_server", { + method: "POST", + body: data, + }); assert(response.body !== null); const firstReader = await response.body.getReader(); @@ -801,13 +796,10 @@ unitTest( async function fetchBodyReaderWithReadCancelAndNewReader(): Promise<void> { const data = "a".repeat(1 << 10); - const response = await fetch( - "http://localhost:4545/cli/tests/echo_server", - { - method: "POST", - body: data, - } - ); + const response = await fetch("http://localhost:4545/echo_server", { + method: "POST", + body: data, + }); assert(response.body !== null); const firstReader = await response.body.getReader(); @@ -848,7 +840,7 @@ unitTest( for (const status of nullBodyStatus) { const headers = new Headers([["x-status", String(status)]]); - const res = await fetch("http://localhost:4545/cli/tests/echo_server", { + const res = await fetch("http://localhost:4545/echo_server", { body: "deno", method: "POST", headers, diff --git a/cli/tests/x_deno_warning.js.header b/cli/tests/x_deno_warning.js.header deleted file mode 100644 index 9a8ba0190..000000000 --- a/cli/tests/x_deno_warning.js.header +++ /dev/null @@ -1,2 +0,0 @@ -Content-Type: application/javascript -X-Deno-Warning: foobar
\ No newline at end of file |