-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.test.ts
72 lines (57 loc) · 1.51 KB
/
terminal.test.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { DockerClient } from "../lib";
import { collect } from "./utils";
test("terminal", async () => {
const client = await DockerClient({
baseURL: new URL("unix:/var/run/docker.sock"),
});
const pullResp = await client.Image.Create({
query: {
fromImage: "debian",
tag: "latest",
},
});
await collect(pullResp);
const createResp = await client.Container.Create({
body: {
Image: "debian",
Cmd: ["bash"],
Tty: true,
},
});
await client.Container.Start({
path: { id: createResp.Id },
});
const execResp = await client.Exec.Container({
path: { id: createResp.Id },
body: {
Privileged: false, // TODO: this shouldn't be mandatory
Cmd: ["/bin/bash"],
Tty: false,
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
},
});
const terminal = await client.Exec.Start({
path: { id: execResp.Id },
// TODO: initial body
});
const output: string[] = [];
terminal.output.subscribe((value) => output.push(value));
terminal.input.next("whoami");
terminal.input.next("uname -s");
await delay(1);
expect(output).toHaveLength(2);
expect(output[0].trim()).toEqual("root");
expect(output[1].trim()).toEqual("Linux");
terminal.close();
await client.Container.Stop({
path: { id: createResp.Id },
});
await client.Container.Delete({
path: { id: createResp.Id },
});
});
async function delay(s: number) {
return new Promise((resolve) => setTimeout(resolve, s * 1000));
}