-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathintegration_tests.rs
More file actions
318 lines (259 loc) · 10.3 KB
/
integration_tests.rs
File metadata and controls
318 lines (259 loc) · 10.3 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
mod assertions;
mod docker;
mod fs;
mod install {
use test_case::test_case;
use crate::fs::{any_temp_dir, path_to_string};
use assert_cmd::cargo_bin_cmd;
use crate::assertions::{assert_file_exists, assert_file_not_exists};
#[cfg(target_family = "unix")]
#[test_case("helloworld.tar.gz", "helloworld"; "tar gzip")]
#[test_case("helloworld.tgz", "helloworld"; "tar tgz")]
#[test_case("helloworld.tar.bz2", "helloworld"; "tar bzip2")]
#[test_case("helloworld.tar.xz", "helloworld"; "tar xz")]
#[test_case("helloworld.zip", "helloworld"; "zip")]
#[test_case("helloworld.7z", "helloworld"; "7zip")]
#[test_case("helloworld-compressed-unix.gz", "helloworld-compressed-unix"; "gzip")]
#[test_case("helloworld-compressed-unix.bz2", "helloworld-compressed-unix"; "bzip2")]
#[test_case("helloworld-compressed-unix.xz", "helloworld-compressed-unix"; "xz")]
#[test_case("helloworld-unix", "helloworld-unix"; "executable")]
fn installed_successfully(asset: &str, expected_executable: &str) {
let output_dir = any_temp_dir();
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.arg("-i")
.args(["-s", asset])
.args(["-o", &path_to_string(output_dir.clone())])
.arg("devmatteini/dra-tests")
.assert();
result
.success()
.stdout(predicates::str::contains("Installation completed"));
assert_file_exists(output_dir.join(expected_executable).as_path());
}
#[cfg(target_os = "windows")]
#[test_case("helloworld-windows.tar.gz", "helloworld.exe"; "tar gzip")]
#[test_case("helloworld-windows.zip", "helloworld.exe"; "zip")]
#[test_case("helloworld-windows.7z", "helloworld.exe"; "7zip")]
#[test_case("helloworld-compressed-windows.gz", "helloworld-compressed-windows"; "gzip")]
#[test_case("helloworld-compressed-windows.bz2", "helloworld-compressed-windows"; "bzip2")]
#[test_case("helloworld-compressed-windows.xz", "helloworld-compressed-windows"; "xz")]
#[test_case("helloworld-windows.exe", "helloworld-windows.exe"; "executable")]
fn installed_successfully(asset: &str, expected_executable: &str) {
let output_dir = any_temp_dir();
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.arg("-i")
.args(["-s", asset])
.args(["-o", &path_to_string(output_dir.clone())])
.arg("devmatteini/dra-tests")
.assert();
result
.success()
.stdout(predicates::str::contains("Installation completed"));
assert_file_exists(output_dir.join(expected_executable).as_path());
}
#[test]
fn no_executable() {
let output_dir = path_to_string(any_temp_dir());
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.arg("-i")
.args(["-s", "no_executable.tar.gz"])
.args(["-o", &output_dir])
.arg("devmatteini/dra-tests")
.assert();
result
.failure()
.stderr(predicates::str::contains("No executables found"));
}
#[cfg(target_family = "unix")]
#[test_case("helloworld-many-executables-unix.tar.gz", "helloworld-v2"; "install helloworld-v2")]
fn install_file_successfully(asset: &str, file: &str) {
let temp_dir = any_temp_dir();
let expected_installed_file = temp_dir.join(file);
let output_dir = path_to_string(temp_dir);
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-I", file])
.args(["-s", asset])
.args(["-o", &output_dir])
.arg("devmatteini/dra-tests")
.assert();
result
.success()
.stdout(predicates::str::contains("Installation completed"));
assert_file_exists(&expected_installed_file);
}
#[cfg(target_os = "windows")]
#[test_case("helloworld-many-executables-windows.zip", "helloworld-v2.exe"; "install helloworld-v2.exe")]
fn install_file_successfully(asset: &str, file: &str) {
let temp_dir = any_temp_dir();
let expected_installed_file = temp_dir.join(file);
let output_dir = path_to_string(temp_dir);
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-I", file])
.args(["-s", asset])
.args(["-o", &output_dir])
.arg("devmatteini/dra-tests")
.assert();
result
.success()
.stdout(predicates::str::contains("Installation completed"));
assert_file_exists(&expected_installed_file);
}
#[cfg(target_family = "unix")]
#[test]
fn install_multiple_files_successfully() {
let output_dir = any_temp_dir();
let selected_asset = "helloworld-many-executables-unix.tar.gz";
let exec1 = "random-script";
let exec2 = "helloworld-v2";
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-s", selected_asset])
.args(["-o", &path_to_string(output_dir.clone())])
.args(["-I", exec1])
.args(["-I", exec2])
.arg("devmatteini/dra-tests")
.assert();
result
.success()
.stdout(predicates::str::contains("Installation completed"));
assert_file_exists(output_dir.join(exec1).as_path());
assert_file_exists(output_dir.join(exec2).as_path());
}
#[cfg(target_family = "windows")]
#[test]
fn install_multiple_files_successfully() {
let output_dir = any_temp_dir();
let selected_asset = "helloworld-many-executables-windows.zip";
let exec1 = "random-script.exe";
let exec2 = "helloworld-v2.exe";
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-s", selected_asset])
.args(["-o", &path_to_string(output_dir.clone())])
.args(["-I", exec1])
.args(["-I", exec2])
.arg("devmatteini/dra-tests")
.assert();
result
.success()
.stdout(predicates::str::contains("Installation completed"));
assert_file_exists(output_dir.join(exec1).as_path());
assert_file_exists(output_dir.join(exec2).as_path());
}
#[cfg(target_family = "unix")]
#[test]
fn partially_install_multiple_files() {
let output_dir = any_temp_dir();
let selected_asset = "helloworld-many-executables-unix.tar.gz";
let exec1 = "wrong-exec";
let exec2 = "helloworld-v2";
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-s", selected_asset])
.args(["-o", &path_to_string(output_dir.clone())])
.args(["-I", exec1])
.args(["-I", exec2])
.arg("devmatteini/dra-tests")
.assert();
result.failure().stderr(predicates::str::contains(format!(
"Executable {} not found",
exec1
)));
assert_file_not_exists(output_dir.join(exec1).as_path());
assert_file_exists(output_dir.join(exec2).as_path());
}
#[cfg(target_family = "windows")]
#[test]
fn partially_install_multiple_files() {
let output_dir = any_temp_dir();
let selected_asset = "helloworld-many-executables-windows.zip";
let exec1 = "wrong-exec.exe";
let exec2 = "helloworld-v2.exe";
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-s", selected_asset])
.args(["-o", &path_to_string(output_dir.clone())])
.args(["-I", exec1])
.args(["-I", exec2])
.arg("devmatteini/dra-tests")
.assert();
result.failure().stderr(predicates::str::contains(format!(
"Executable {} not found",
exec1
)));
assert_file_not_exists(output_dir.join(exec1).as_path());
assert_file_exists(output_dir.join(exec2).as_path());
}
}
mod download {
use crate::fs::{any_temp_dir, any_temp_file, path_to_string};
use assert_cmd::cargo_bin_cmd;
#[test]
fn download_source_code_successfully() {
let output_file = path_to_string(any_temp_file("dra-tests-src"));
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-s", "dra-tests-{tag}-source-code.tar.gz"])
.args(["-o", &output_file])
.arg("devmatteini/dra-tests")
.assert();
let expected = format!("Saved to: {}", &output_file);
result.success().stdout(predicates::str::contains(expected));
}
#[test]
fn cannot_use_display_name_to_select_asset() {
let output_file = path_to_string(any_temp_file("dra-tests-any"));
let mut cmd = cargo_bin_cmd!("dra");
let result = cmd
.arg("download")
.args(["-s", "Source code (tar.gz)"])
.args(["-o", &output_file])
.arg("devmatteini/dra-tests")
.assert();
result.failure().stderr(predicates::str::contains(
"No asset found for Source code (tar.gz)",
));
}
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
#[test]
fn automatic_download() {
let temp_dir = any_temp_dir();
let mut cmd = cargo_bin_cmd!("dra");
cmd.current_dir(&temp_dir)
.arg("download")
.arg("-a")
.arg("devmatteini/dra-tests")
.assert()
.success();
let expected_asset = if cfg!(target_os = "linux") {
"helloworld-x86_64-linux.tar.gz"
} else if cfg!(target_os = "windows") {
"helloworld-x86_64-windows.tar.gz"
} else if cfg!(target_os = "macos") {
"helloworld-aarch64-apple-darwin.tar.gz"
} else {
panic!("This test should only run on linux, macOS and windows")
};
assert!(
temp_dir.join(expected_asset).exists(),
"Expected asset '{}' not exists in {}",
expected_asset,
temp_dir.display()
);
}
}