summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/net_test.ts7
-rw-r--r--cli/tests/unit/serve_test.ts35
-rw-r--r--cli/tests/unit/test_util.ts7
3 files changed, 42 insertions, 7 deletions
diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts
index 54edf31fc..2a98b5e26 100644
--- a/cli/tests/unit/net_test.ts
+++ b/cli/tests/unit/net_test.ts
@@ -9,8 +9,8 @@ import {
delay,
execCode,
execCode2,
+ tmpUnixSocketPath,
} from "./test_util.ts";
-import { join } from "../../../test_util/std/path/mod.ts";
// Since these tests may run in parallel, ensure this port is unique to this file
const listenPort = 4503;
@@ -49,11 +49,6 @@ Deno.test(
},
);
-function tmpUnixSocketPath(): string {
- const folder = Deno.makeTempDirSync();
- return join(folder, "socket");
-}
-
Deno.test(
{
ignore: Deno.build.os === "windows",
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts
index 193b04ed1..6f58db006 100644
--- a/cli/tests/unit/serve_test.ts
+++ b/cli/tests/unit/serve_test.ts
@@ -15,6 +15,7 @@ import {
deferred,
execCode,
fail,
+ tmpUnixSocketPath,
} from "./test_util.ts";
// Since these tests may run in parallel, ensure this port is unique to this file
@@ -3715,3 +3716,37 @@ async function curlRequestWithStdErr(args: string[]) {
assert(success);
return [new TextDecoder().decode(stdout), new TextDecoder().decode(stderr)];
}
+
+Deno.test(
+ {
+ ignore: Deno.build.os === "windows",
+ permissions: { run: true, read: true, write: true },
+ },
+ async function httpServerUnixDomainSocket() {
+ const d = deferred();
+ const ac = new AbortController();
+ const filePath = tmpUnixSocketPath();
+ const server = Deno.serve(
+ {
+ signal: ac.signal,
+ path: filePath,
+ onListen(info) {
+ d.resolve(info);
+ },
+ onError: createOnErrorCb(ac),
+ },
+ (_req, { remoteAddr }) => {
+ assertEquals(remoteAddr, { path: filePath, transport: "unix" });
+ return new Response("hello world!");
+ },
+ );
+
+ assertEquals(await d, { path: filePath });
+ assertEquals(
+ "hello world!",
+ await curlRequest(["--unix-socket", filePath, "http://localhost"]),
+ );
+ ac.abort();
+ await server.finished;
+ },
+);
diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts
index 23713faf4..de1e8e8c5 100644
--- a/cli/tests/unit/test_util.ts
+++ b/cli/tests/unit/test_util.ts
@@ -2,7 +2,7 @@
import * as colors from "../../../test_util/std/fmt/colors.ts";
export { colors };
-import { resolve } from "../../../test_util/std/path/mod.ts";
+import { join, resolve } from "../../../test_util/std/path/mod.ts";
export {
assert,
assertEquals,
@@ -81,3 +81,8 @@ export function execCode2(code: string) {
},
};
}
+
+export function tmpUnixSocketPath(): string {
+ const folder = Deno.makeTempDirSync();
+ return join(folder, "socket");
+}