2020-03-01 19:51:54 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2020-06-12 15:23:38 -04:00
|
|
|
const name = Deno.args[0];
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore no-explicit-any
|
2020-08-24 19:43:54 -04:00
|
|
|
const test: { [key: string]: (...args: any[]) => void | Promise<void> } = {
|
2020-03-01 19:51:54 -05:00
|
|
|
read(files: string[]): void {
|
2020-06-12 15:23:38 -04:00
|
|
|
files.forEach((file) => Deno.readFileSync(file));
|
2020-03-01 19:51:54 -05:00
|
|
|
},
|
|
|
|
write(files: string[]): void {
|
2020-03-28 13:03:49 -04:00
|
|
|
files.forEach((file) =>
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.writeFileSync(file, new Uint8Array(0), { append: true })
|
2020-03-01 19:51:54 -05:00
|
|
|
);
|
|
|
|
},
|
2021-01-07 13:06:08 -05:00
|
|
|
netFetch(urls: string[]): void {
|
|
|
|
urls.forEach((url) => fetch(url));
|
2020-03-01 19:51:54 -05:00
|
|
|
},
|
|
|
|
netListen(endpoints: string[]): void {
|
2020-03-28 13:03:49 -04:00
|
|
|
endpoints.forEach((endpoint) => {
|
2020-06-26 08:09:02 -04:00
|
|
|
const index = endpoint.lastIndexOf(":");
|
|
|
|
const [hostname, port] = [
|
|
|
|
endpoint.substr(0, index),
|
|
|
|
endpoint.substr(index + 1),
|
|
|
|
];
|
2020-03-01 19:51:54 -05:00
|
|
|
const listener = Deno.listen({
|
|
|
|
transport: "tcp",
|
|
|
|
hostname,
|
2020-03-28 13:03:49 -04:00
|
|
|
port: parseInt(port, 10),
|
2020-03-01 19:51:54 -05:00
|
|
|
});
|
|
|
|
listener.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async netConnect(endpoints: string[]): Promise<void> {
|
|
|
|
for (const endpoint of endpoints) {
|
2020-06-26 08:09:02 -04:00
|
|
|
const index = endpoint.lastIndexOf(":");
|
|
|
|
const [hostname, port] = [
|
|
|
|
endpoint.substr(0, index),
|
|
|
|
endpoint.substr(index + 1),
|
|
|
|
];
|
2020-03-01 19:51:54 -05:00
|
|
|
const listener = await Deno.connect({
|
|
|
|
transport: "tcp",
|
|
|
|
hostname,
|
2020-03-28 13:03:49 -04:00
|
|
|
port: parseInt(port, 10),
|
2020-03-01 19:51:54 -05:00
|
|
|
});
|
|
|
|
listener.close();
|
|
|
|
}
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-01 19:51:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!test[name]) {
|
|
|
|
console.log("Unknown test:", name);
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.exit(1);
|
2020-03-01 19:51:54 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
test[name](Deno.args.slice(1));
|