-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
196 lines (181 loc) · 6.33 KB
/
index.test.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const fs = require('fs');
const tmp = require('tmp');
const vmtest = require('./vmtest');
test('validate good args', async () => {
const args = {
kernel: './bzimage',
kernel_url: '',
kernel_args: 'console=ttyS0',
image: '',
image_url: '',
command: '/bin/echo hello',
};
expect(async () => {
await vmtest.validateArgs(args)
}).not.toThrow();
});
test('validate bad args', async () => {
const badKernelArgs = {
kernel: './bzimage',
kernel_url: 'https://example.com/bzimage',
kernel_args: 'console=ttyS0',
image: '',
image_url: '',
command: '/bin/echo hello',
};
await expect(vmtest.validateArgs(badKernelArgs)).rejects.toThrow('Cannot specify both');
const badImageArgs = {
kernel: '',
kernel_url: '',
kernel_args: '',
image: './image',
image_url: 'https://example.com/image',
command: '/bin/echo hello',
};
await expect(vmtest.validateArgs(badImageArgs)).rejects.toThrow('Cannot specify both');
});
test('test os-release ubuntu22', async () => {
const osRelease = tmp.fileSync();
const osReleaseContents = 'ID=ubuntu\n' +
'PRETTY_NAME="Ubuntu 22.04.2 LTS"\n' +
'NAME="Ubuntu"\n' +
'VERSION_ID="22.04"\n' +
'VERSION="22.04.2 LTS (Jammy Jellyfish)"\n' +
'VERSION_CODENAME=jammy\n' +
'ID=ubuntu\n' +
'ID_LIKE=debian\n' +
'HOME_URL="https://www.ubuntu.com/"\n' +
'SUPPORT_URL="https://help.ubuntu.com/"\n' +
'BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"\n' +
'PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"\n' +
'UBUNTU_CODENAME=jammy\n';
fs.writeFileSync(osRelease.name, osReleaseContents);
expect(async () => {
await vmtest.checkOnUbuntu(osRelease.name)
}).not.toThrow();
});
test('test os-release ubuntu20', async () => {
const osRelease = tmp.fileSync();
const osReleaseContents = 'NAME="Ubuntu"\n' +
'VERSION="20.04.6 LTS (Focal Fossa)"\n' +
'ID=ubuntu\n' +
'ID_LIKE=debian\n' +
'PRETTY_NAME="Ubuntu 20.04.6 LTS"\n' +
'VERSION_ID="20.04"\n' +
'HOME_URL="https://www.ubuntu.com/"\n' +
'SUPPORT_URL="https://help.ubuntu.com/"\n' +
'BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"\n' +
'PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"\n' +
'VERSION_CODENAME=focal\n' +
'UBUNTU_CODENAME=focal\n';
fs.writeFileSync(osRelease.name, osReleaseContents);
expect(async () => {
await vmtest.checkOnUbuntu(osRelease.name)
}).not.toThrow();
});
test('test os-release arch linux', async () => {
const osRelease = tmp.fileSync();
const osReleaseContents = 'NAME="Arch Linux"\n' +
'PRETTY_NAME="Arch Linux"\n' +
'ID=arch\n' +
'BUILD_ID=rolling\n' +
'ANSI_COLOR="38;2;23;147;209"\n' +
'HOME_URL="https://archlinux.org/"\n' +
'DOCUMENTATION_URL="https://wiki.archlinux.org/"\n' +
'SUPPORT_URL="https://bbs.archlinux.org/"\n' +
'BUG_REPORT_URL="https://bugs.archlinux.org/"\n' +
'PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"\n' +
'LOGO=archlinux-logo\n';
fs.writeFileSync(osRelease.name, osReleaseContents);
await expect(vmtest.checkOnUbuntu(osRelease.name)).rejects.toThrow("only works on Ubuntu runners");
});
test('test invalid os-release', async () => {
const osRelease = tmp.fileSync();
const osReleaseContents = 'asdfasdf'
fs.writeFileSync(osRelease.name, osReleaseContents);
await expect(vmtest.checkOnUbuntu(osRelease.name)).rejects.toThrow("Invalid line in");
});
test('materialize image args', async () => {
const args = {
name: 'test',
image: './foo.img',
image_url: '',
uefi: 'true',
kernel: '',
kernel_url: '',
kernel_args: '',
command: '/bin/true',
};
const config = tmp.fileSync();
await vmtest.materializeConfig(args, config.name, null);
const contents = fs.readFileSync(config.name, 'utf8');
const expected = '[[target]]\n' +
'name = "test"\n' +
'image = "./foo.img"\n' +
'uefi = true\n' +
`command = '''/bin/true'''`;
expect(contents).toBe(expected);
});
test('materialize downloaded image args', async () => {
const args = {
name: 'test',
image: '',
image_url: 'https://example.com/image',
uefi: 'true',
kernel: '',
kernel_url: '',
kernel_args: '',
command: '/bin/true',
};
const config = tmp.fileSync();
await vmtest.materializeConfig(args, config.name, '/tmp/image');
const contents = fs.readFileSync(config.name, 'utf8');
const expected = '[[target]]\n' +
'name = "test"\n' +
'image = "/tmp/image"\n' +
'uefi = true\n' +
`command = '''/bin/true'''`;
expect(contents).toBe(expected);
});
test('materialize kernel args', async () => {
const args = {
name: 'test',
image: '',
image_url: '',
uefi: 'false',
kernel: './bzImage-6.0',
kernel_url: '',
kernel_args: 'console=ttyS0',
command: '/bin/true',
};
const config = tmp.fileSync();
await vmtest.materializeConfig(args, config.name, null);
const contents = fs.readFileSync(config.name, 'utf8');
const expected = '[[target]]\n' +
'name = "test"\n' +
'kernel = "./bzImage-6.0"\n' +
'kernel_args = "console=ttyS0"\n' +
`command = '''/bin/true'''`;
expect(contents).toBe(expected);
});
test('materialize downloaded kernel args', async () => {
const args = {
name: 'test',
image: '',
image_url: '',
uefi: 'false',
kernel: '',
kernel_url: 'https://example.com/bzImage-6.0',
kernel_args: 'console=ttyS0',
command: '/bin/true',
};
const config = tmp.fileSync();
await vmtest.materializeConfig(args, config.name, '/tmp/bzImage-6.0');
const contents = fs.readFileSync(config.name, 'utf8');
const expected = '[[target]]\n' +
'name = "test"\n' +
'kernel = "/tmp/bzImage-6.0"\n' +
'kernel_args = "console=ttyS0"\n' +
`command = '''/bin/true'''`;
expect(contents).toBe(expected);
});