From 432792a46c71b402408e1bed0affdb1c3a90d8c6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 14 May 2024 12:47:57 -0400 Subject: chore: 045_proxy output stdout & stderr on failure (#23810) Part of https://github.com/denoland/deno/issues/23624 --- tests/integration/run_tests.rs | 6 - tests/specs/run/045_proxy/__test__.jsonc | 4 + .../run/045_proxy/programmatic_proxy_client.ts | 16 +++ tests/specs/run/045_proxy/proxy_client.ts | 5 + tests/specs/run/045_proxy/proxy_test.ts | 129 +++++++++++++++++++++ tests/specs/run/045_proxy/proxy_test.ts.out | 6 + .../testdata/run/045_programmatic_proxy_client.ts | 16 --- tests/testdata/run/045_proxy_client.ts | 5 - tests/testdata/run/045_proxy_test.ts | 121 ------------------- tests/testdata/run/045_proxy_test.ts.out | 6 - tools/lint.js | 2 +- 11 files changed, 161 insertions(+), 155 deletions(-) create mode 100644 tests/specs/run/045_proxy/__test__.jsonc create mode 100644 tests/specs/run/045_proxy/programmatic_proxy_client.ts create mode 100644 tests/specs/run/045_proxy/proxy_client.ts create mode 100644 tests/specs/run/045_proxy/proxy_test.ts create mode 100644 tests/specs/run/045_proxy/proxy_test.ts.out delete mode 100644 tests/testdata/run/045_programmatic_proxy_client.ts delete mode 100644 tests/testdata/run/045_proxy_client.ts delete mode 100644 tests/testdata/run/045_proxy_test.ts delete mode 100644 tests/testdata/run/045_proxy_test.ts.out diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 8a24603b3..ed07fab96 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -234,12 +234,6 @@ itest!(_044_bad_resource { exit_code: 1, }); -itest!(_045_proxy { - args: "run -L debug --allow-net --allow-env --allow-run --allow-read --reload --quiet run/045_proxy_test.ts", - output: "run/045_proxy_test.ts.out", - http_server: true, -}); - itest!(_046_tsx { args: "run --quiet --reload run/046_jsx_test.tsx", output: "run/046_jsx_test.tsx.out", diff --git a/tests/specs/run/045_proxy/__test__.jsonc b/tests/specs/run/045_proxy/__test__.jsonc new file mode 100644 index 000000000..d4fb7f60c --- /dev/null +++ b/tests/specs/run/045_proxy/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run -L debug --allow-net --allow-env --allow-run --allow-read --reload --quiet proxy_test.ts", + "output": "proxy_test.ts.out" +} diff --git a/tests/specs/run/045_proxy/programmatic_proxy_client.ts b/tests/specs/run/045_proxy/programmatic_proxy_client.ts new file mode 100644 index 000000000..73af590c7 --- /dev/null +++ b/tests/specs/run/045_proxy/programmatic_proxy_client.ts @@ -0,0 +1,16 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +const client = Deno.createHttpClient({ + proxy: { + url: "http://localhost:4555", + basicAuth: { username: "username", password: "password" }, + }, +}); + +const res = await fetch( + "http://localhost:4545/run/045_mod.ts", + { client }, +); +console.log(`Response http: ${await res.text()}`); + +client.close(); diff --git a/tests/specs/run/045_proxy/proxy_client.ts b/tests/specs/run/045_proxy/proxy_client.ts new file mode 100644 index 000000000..41deae2a5 --- /dev/null +++ b/tests/specs/run/045_proxy/proxy_client.ts @@ -0,0 +1,5 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +const res = await fetch( + "http://localhost:4545/run/045_mod.ts", +); +console.log(`Response http: ${await res.text()}`); diff --git a/tests/specs/run/045_proxy/proxy_test.ts b/tests/specs/run/045_proxy/proxy_test.ts new file mode 100644 index 000000000..d3386f0d7 --- /dev/null +++ b/tests/specs/run/045_proxy/proxy_test.ts @@ -0,0 +1,129 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { Server } from "../../../util/std/http/server.ts"; + +const addr = Deno.args[1] || "localhost:4555"; + +async function proxyServer() { + const [hostname, p] = addr.split(":"); + const port = parseInt(p ?? 4555); + const server = new Server({ hostname, port, handler }); + console.log(`Proxy server listening on http://${addr}/`); + await server.listenAndServe(); +} + +async function handler(req: Request): Promise { + console.log(`Proxy request to: ${req.url}`); + const headers = new Headers(req.headers); + const proxyAuthorization = headers.get("proxy-authorization"); + if (proxyAuthorization) { + console.log(`proxy-authorization: ${proxyAuthorization}`); + headers.delete("proxy-authorization"); + } + const resp = await fetch(req.url, { + method: req.method, + headers: headers, + }); + return new Response(new Uint8Array(await resp.arrayBuffer()), { + status: resp.status, + headers: resp.headers, + }); +} + +function assertSuccessOutput(output: Deno.CommandOutput) { + if (output.code !== 0) { + console.error("STDOUT", new TextDecoder().decode(output.stdout)); + console.error("STDERR", new TextDecoder().decode(output.stderr)); + throw new Error(`Expected exit code 0, was ${output.code}`); + } +} + +async function testFetch() { + const output = await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "--quiet", + "--reload", + "--allow-net", + "proxy_client.ts", + ], + env: { + HTTP_PROXY: `http://${addr}`, + }, + }).output(); + + assertSuccessOutput(output); +} + +async function testModuleDownload() { + const output = await new Deno.Command(Deno.execPath(), { + args: [ + "cache", + "--reload", + "--quiet", + "http://localhost:4545/run/045_mod.ts", + ], + env: { + HTTP_PROXY: `http://${addr}`, + }, + }).output(); + + assertSuccessOutput(output); +} + +async function testFetchNoProxy() { + const output = await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "--quiet", + "--reload", + "--allow-net", + "proxy_client.ts", + ], + env: { + HTTP_PROXY: "http://not.exising.proxy.server", + NO_PROXY: "localhost", + }, + }).output(); + + assertSuccessOutput(output); +} + +async function testModuleDownloadNoProxy() { + const output = await new Deno.Command(Deno.execPath(), { + args: [ + "cache", + "--reload", + "--quiet", + "http://localhost:4545/run/045_mod.ts", + ], + env: { + HTTP_PROXY: "http://not.exising.proxy.server", + NO_PROXY: "localhost", + }, + }).output(); + + assertSuccessOutput(output); +} + +async function testFetchProgrammaticProxy() { + const output = await new Deno.Command(Deno.execPath(), { + args: [ + "run", + "--quiet", + "--reload", + "--allow-net=localhost:4545,localhost:4555", + "--unstable", + "programmatic_proxy_client.ts", + ], + }).output(); + + assertSuccessOutput(output); +} + +proxyServer(); +await testFetch(); +await testModuleDownload(); +await testFetchNoProxy(); +await testModuleDownloadNoProxy(); +await testFetchProgrammaticProxy(); +Deno.exit(0); diff --git a/tests/specs/run/045_proxy/proxy_test.ts.out b/tests/specs/run/045_proxy/proxy_test.ts.out new file mode 100644 index 000000000..a1e567a14 --- /dev/null +++ b/tests/specs/run/045_proxy/proxy_test.ts.out @@ -0,0 +1,6 @@ +Proxy server listening on [WILDCARD] +Proxy request to: http://localhost:4545/run/045_mod.ts +Proxy request to: http://localhost:4545/run/045_mod.ts +Proxy request to: http://localhost:4545/run/045_output.ts +Proxy request to: http://localhost:4545/run/045_mod.ts +proxy-authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= diff --git a/tests/testdata/run/045_programmatic_proxy_client.ts b/tests/testdata/run/045_programmatic_proxy_client.ts deleted file mode 100644 index 73af590c7..000000000 --- a/tests/testdata/run/045_programmatic_proxy_client.ts +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. - -const client = Deno.createHttpClient({ - proxy: { - url: "http://localhost:4555", - basicAuth: { username: "username", password: "password" }, - }, -}); - -const res = await fetch( - "http://localhost:4545/run/045_mod.ts", - { client }, -); -console.log(`Response http: ${await res.text()}`); - -client.close(); diff --git a/tests/testdata/run/045_proxy_client.ts b/tests/testdata/run/045_proxy_client.ts deleted file mode 100644 index 41deae2a5..000000000 --- a/tests/testdata/run/045_proxy_client.ts +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -const res = await fetch( - "http://localhost:4545/run/045_mod.ts", -); -console.log(`Response http: ${await res.text()}`); diff --git a/tests/testdata/run/045_proxy_test.ts b/tests/testdata/run/045_proxy_test.ts deleted file mode 100644 index fcb898c77..000000000 --- a/tests/testdata/run/045_proxy_test.ts +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { Server } from "../../../tests/util/std/http/server.ts"; -import { assertEquals } from "../../../tests/util/std/assert/mod.ts"; - -const addr = Deno.args[1] || "localhost:4555"; - -async function proxyServer() { - const [hostname, p] = addr.split(":"); - const port = parseInt(p ?? 4555); - const server = new Server({ hostname, port, handler }); - console.log(`Proxy server listening on http://${addr}/`); - await server.listenAndServe(); -} - -async function handler(req: Request): Promise { - console.log(`Proxy request to: ${req.url}`); - const headers = new Headers(req.headers); - const proxyAuthorization = headers.get("proxy-authorization"); - if (proxyAuthorization) { - console.log(`proxy-authorization: ${proxyAuthorization}`); - headers.delete("proxy-authorization"); - } - const resp = await fetch(req.url, { - method: req.method, - headers: headers, - }); - return new Response(new Uint8Array(await resp.arrayBuffer()), { - status: resp.status, - headers: resp.headers, - }); -} - -async function testFetch() { - const { code } = await new Deno.Command(Deno.execPath(), { - args: [ - "run", - "--quiet", - "--reload", - "--allow-net", - "run/045_proxy_client.ts", - ], - env: { - HTTP_PROXY: `http://${addr}`, - }, - }).output(); - - assertEquals(code, 0); -} - -async function testModuleDownload() { - const { code } = await new Deno.Command(Deno.execPath(), { - args: [ - "cache", - "--reload", - "--quiet", - "http://localhost:4545/run/045_mod.ts", - ], - env: { - HTTP_PROXY: `http://${addr}`, - }, - }).output(); - - assertEquals(code, 0); -} - -async function testFetchNoProxy() { - const { code } = await new Deno.Command(Deno.execPath(), { - args: [ - "run", - "--quiet", - "--reload", - "--allow-net", - "run/045_proxy_client.ts", - ], - env: { - HTTP_PROXY: "http://not.exising.proxy.server", - NO_PROXY: "localhost", - }, - }).output(); - - assertEquals(code, 0); -} - -async function testModuleDownloadNoProxy() { - const { code } = await new Deno.Command(Deno.execPath(), { - args: [ - "cache", - "--reload", - "--quiet", - "http://localhost:4545/run/045_mod.ts", - ], - env: { - HTTP_PROXY: "http://not.exising.proxy.server", - NO_PROXY: "localhost", - }, - }).output(); - - assertEquals(code, 0); -} - -async function testFetchProgrammaticProxy() { - const { code } = await new Deno.Command(Deno.execPath(), { - args: [ - "run", - "--quiet", - "--reload", - "--allow-net=localhost:4545,localhost:4555", - "--unstable", - "run/045_programmatic_proxy_client.ts", - ], - }).output(); - assertEquals(code, 0); -} - -proxyServer(); -await testFetch(); -await testModuleDownload(); -await testFetchNoProxy(); -await testModuleDownloadNoProxy(); -await testFetchProgrammaticProxy(); -Deno.exit(0); diff --git a/tests/testdata/run/045_proxy_test.ts.out b/tests/testdata/run/045_proxy_test.ts.out deleted file mode 100644 index a1e567a14..000000000 --- a/tests/testdata/run/045_proxy_test.ts.out +++ /dev/null @@ -1,6 +0,0 @@ -Proxy server listening on [WILDCARD] -Proxy request to: http://localhost:4545/run/045_mod.ts -Proxy request to: http://localhost:4545/run/045_mod.ts -Proxy request to: http://localhost:4545/run/045_output.ts -Proxy request to: http://localhost:4545/run/045_mod.ts -proxy-authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= diff --git a/tools/lint.js b/tools/lint.js index 0fe96b049..aa3b417cc 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -221,7 +221,7 @@ async function ensureNoNewITests() { "pm_tests.rs": 0, "publish_tests.rs": 0, "repl_tests.rs": 0, - "run_tests.rs": 373, + "run_tests.rs": 372, "shared_library_tests.rs": 0, "task_tests.rs": 30, "test_tests.rs": 77, -- cgit v1.2.3