summaryrefslogtreecommitdiff
path: root/tools/complex_permissions_test.ts
blob: dd65a0e330cc794d383de820398b864db8ea02af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
const { args, readFileSync, writeFileSync, exit } = Deno;

const name = args[1];
const test: (args: string[]) => void = {
  read(files: string[]): void {
    files.forEach(file => readFileSync(file));
  },
  write(files: string[]): void {
    files.forEach(file =>
      writeFileSync(file, new Uint8Array(0), { append: true })
    );
  },
  netFetch(hosts: string[]): void {
    hosts.forEach(host => fetch(host));
  },
  netListen(hosts: string[]): void {
    hosts.forEach(host => {
      const listener = Deno.listen("tcp", host);
      listener.close();
    });
  },
  async netDial(hosts: string[]): Promise<void> {
    for (const host of hosts) {
      const listener = await Deno.dial("tcp", host);
      listener.close();
    }
  }
}[name];

if (!test) {
  console.log("Unknown test:", name);
  exit(1);
}

test(args.slice(2));