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> } = {
|
2021-08-05 07:08:58 -04:00
|
|
|
read(files: string[]) {
|
2020-06-12 15:23:38 -04:00
|
|
|
files.forEach((file) => Deno.readFileSync(file));
|
2020-03-01 19:51:54 -05:00
|
|
|
},
|
2021-08-05 07:08:58 -04:00
|
|
|
write(files: string[]) {
|
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-08-05 07:08:58 -04:00
|
|
|
netFetch(urls: string[]) {
|
2021-01-07 13:06:08 -05:00
|
|
|
urls.forEach((url) => fetch(url));
|
2020-03-01 19:51:54 -05:00
|
|
|
},
|
2021-08-05 07:08:58 -04:00
|
|
|
netListen(endpoints: string[]) {
|
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();
|
|
|
|
});
|
|
|
|
},
|
2021-08-05 07:08:58 -04:00
|
|
|
async netConnect(endpoints: string[]) {
|
2020-03-01 19:51:54 -05:00
|
|
|
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));
|