forked from gmart7t2/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.rs
72 lines (61 loc) Β· 1.49 KB
/
core.rs
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
use super::*;
struct KillOnDrop(std::process::Child);
impl Drop for KillOnDrop {
fn drop(&mut self) {
assert!(Command::new("kill")
.arg(self.0.id().to_string())
.status()
.unwrap()
.success());
}
}
#[test]
#[ignore]
fn preview() {
let port = TcpListener::bind("127.0.0.1:0")
.unwrap()
.local_addr()
.unwrap()
.port();
let examples = fs::read_dir("examples")
.unwrap()
.map(|entry| {
entry
.unwrap()
.path()
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.into()
})
.filter(|example| example != "examples/av1.mp4")
.collect::<Vec<String>>();
let mut args = vec![
"preview".to_string(),
"--http-port".to_string(),
port.to_string(),
];
args.extend(examples.clone());
let builder = CommandBuilder::new(args);
let _child = KillOnDrop(builder.command().spawn().unwrap());
for attempt in 0.. {
if let Ok(response) = reqwest::blocking::get(format!("http://127.0.0.1:{port}/status")) {
if response.status() == 200 {
assert_eq!(response.text().unwrap(), "OK");
break;
}
}
if attempt == 100 {
panic!("Server did not respond to status check",);
}
thread::sleep(Duration::from_millis(500));
}
assert_regex_match!(
reqwest::blocking::get(format!("http://127.0.0.1:{port}/inscriptions"))
.unwrap()
.text()
.unwrap(),
format!(".*(<a href=/inscription/.*){{{}}}.*", examples.len())
);
}