2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2020-09-21 12:26:41 +00:00
|
|
|
|
2021-09-06 08:06:59 +00:00
|
|
|
/** Create dummy `Deno.Conn` object with given base properties. */
|
2020-02-26 15:48:35 +00:00
|
|
|
export function mockConn(base: Partial<Deno.Conn> = {}): Deno.Conn {
|
|
|
|
return {
|
|
|
|
localAddr: {
|
|
|
|
transport: "tcp",
|
|
|
|
hostname: "",
|
2020-03-28 17:03:49 +00:00
|
|
|
port: 0,
|
2020-02-26 15:48:35 +00:00
|
|
|
},
|
|
|
|
remoteAddr: {
|
|
|
|
transport: "tcp",
|
|
|
|
hostname: "",
|
2020-03-28 17:03:49 +00:00
|
|
|
port: 0,
|
2020-02-26 15:48:35 +00:00
|
|
|
},
|
|
|
|
rid: -1,
|
2021-04-05 11:49:05 +00:00
|
|
|
closeWrite: () => {
|
2021-01-15 04:32:27 +00:00
|
|
|
return Promise.resolve();
|
|
|
|
},
|
2020-04-28 16:40:43 +00:00
|
|
|
read: (): Promise<number | null> => {
|
2020-03-20 13:38:34 +00:00
|
|
|
return Promise.resolve(0);
|
2020-02-26 15:48:35 +00:00
|
|
|
},
|
2020-04-02 19:20:17 +00:00
|
|
|
write: (): Promise<number> => {
|
|
|
|
return Promise.resolve(-1);
|
2020-02-26 15:48:35 +00:00
|
|
|
},
|
2022-08-24 01:21:57 +00:00
|
|
|
close: () => {},
|
2022-02-15 16:38:18 +00:00
|
|
|
readable: new ReadableStream({
|
|
|
|
type: "bytes",
|
|
|
|
async pull(_controller) {
|
|
|
|
},
|
|
|
|
cancel() {
|
|
|
|
},
|
|
|
|
autoAllocateChunkSize: 1,
|
|
|
|
}),
|
|
|
|
writable: new WritableStream({
|
|
|
|
async write(_chunk, _controller) {
|
|
|
|
},
|
|
|
|
close() {
|
|
|
|
},
|
|
|
|
abort() {
|
|
|
|
},
|
|
|
|
}),
|
2022-02-03 22:46:48 +00:00
|
|
|
// TODO(ry) Remove the following ts-ignore.
|
|
|
|
// @ts-ignore This was added to workaround incompatibilities between Deno versions.
|
2022-08-24 01:21:57 +00:00
|
|
|
setNoDelay: (_nodelay?: boolean) => {},
|
2022-02-03 22:46:48 +00:00
|
|
|
// @ts-ignore This was added to workaround incompatibilities between Deno versions.
|
2022-08-24 01:21:57 +00:00
|
|
|
setKeepAlive: (_keepalive?: boolean) => {},
|
2020-03-28 17:03:49 +00:00
|
|
|
...base,
|
2020-02-26 15:48:35 +00:00
|
|
|
};
|
|
|
|
}
|