2020-03-01 19:51:54 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
|
|
const { args, readFileSync, writeFileSync, exit } = Deno;
|
|
|
|
|
|
|
|
const name = args[0];
|
|
|
|
const test: { [key: string]: Function } = {
|
|
|
|
read(files: string[]): void {
|
2020-03-28 13:03:49 -04:00
|
|
|
files.forEach((file) => 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-03-01 19:51:54 -05:00
|
|
|
writeFileSync(file, new Uint8Array(0), { append: true })
|
|
|
|
);
|
|
|
|
},
|
|
|
|
netFetch(hosts: string[]): void {
|
2020-03-28 13:03:49 -04:00
|
|
|
hosts.forEach((host) => fetch(host));
|
2020-03-01 19:51:54 -05:00
|
|
|
},
|
|
|
|
netListen(endpoints: string[]): void {
|
2020-03-28 13:03:49 -04:00
|
|
|
endpoints.forEach((endpoint) => {
|
2020-03-01 19:51:54 -05:00
|
|
|
const [hostname, port] = endpoint.split(":");
|
|
|
|
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) {
|
|
|
|
const [hostname, port] = endpoint.split(":");
|
|
|
|
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);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test[name](args.slice(1));
|