2019-05-08 19:20:30 -04:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-09-16 17:25:32 -04:00
|
|
|
const { args, readFileSync, writeFileSync, exit } = Deno;
|
2019-05-08 19:20:30 -04:00
|
|
|
|
|
|
|
const name = args[1];
|
|
|
|
const test: (args: string[]) => void = {
|
2019-09-16 17:25:32 -04:00
|
|
|
read(files: string[]): void {
|
|
|
|
files.forEach(file => readFileSync(file));
|
2019-05-08 19:20:30 -04:00
|
|
|
},
|
2019-09-16 17:25:32 -04:00
|
|
|
write(files: string[]): void {
|
|
|
|
files.forEach(file =>
|
|
|
|
writeFileSync(file, new Uint8Array(0), { append: true })
|
2019-05-08 19:20:30 -04:00
|
|
|
);
|
|
|
|
},
|
2019-09-16 17:25:32 -04:00
|
|
|
netFetch(hosts: string[]): void {
|
|
|
|
hosts.forEach(host => fetch(host));
|
2019-05-23 16:47:55 -04:00
|
|
|
},
|
2019-09-16 17:25:32 -04:00
|
|
|
netListen(hosts: string[]): void {
|
|
|
|
hosts.forEach(host => {
|
2019-09-20 18:32:18 -04:00
|
|
|
const [hostname, port] = host.split(":");
|
|
|
|
const listener = Deno.listen({ hostname, port: Number(port) });
|
2019-09-16 17:25:32 -04:00
|
|
|
listener.close();
|
|
|
|
});
|
2019-05-23 16:47:55 -04:00
|
|
|
},
|
2019-09-16 17:25:32 -04:00
|
|
|
async netDial(hosts: string[]): Promise<void> {
|
2019-05-23 16:47:55 -04:00
|
|
|
for (const host of hosts) {
|
2019-09-20 18:32:18 -04:00
|
|
|
const [hostname, port] = host.split(":");
|
|
|
|
const listener = await Deno.dial({ hostname, port: Number(port) });
|
2019-05-23 16:47:55 -04:00
|
|
|
listener.close();
|
|
|
|
}
|
2019-05-08 19:20:30 -04:00
|
|
|
}
|
|
|
|
}[name];
|
|
|
|
|
|
|
|
if (!test) {
|
|
|
|
console.log("Unknown test:", name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test(args.slice(2));
|