2022-08-23 09:24:42 +03:00
|
|
|
use indexmap::IndexSet;
|
2022-06-12 03:43:50 +03:00
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-06-25 03:15:16 +03:00
|
|
|
macro_rules! assert_resp_paths {
|
2022-06-12 03:43:50 +03:00
|
|
|
($resp:ident) => {
|
2022-06-25 03:15:16 +03:00
|
|
|
assert_resp_paths!($resp, self::fixtures::FILES)
|
2022-06-12 03:43:50 +03:00
|
|
|
};
|
|
|
|
($resp:ident, $files:expr) => {
|
|
|
|
assert_eq!($resp.status(), 200);
|
|
|
|
let body = $resp.text()?;
|
2022-08-03 03:51:12 +03:00
|
|
|
let paths = self::utils::retrieve_index_paths(&body);
|
2022-06-12 03:43:50 +03:00
|
|
|
assert!(!paths.is_empty());
|
|
|
|
for file in $files {
|
|
|
|
assert!(paths.contains(&file.to_string()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! fetch {
|
|
|
|
($method:literal, $url:expr) => {
|
|
|
|
reqwest::blocking::Client::new().request(hyper::Method::from_bytes($method)?, $url)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2022-08-23 09:24:42 +03:00
|
|
|
pub fn retrieve_index_paths(index: &str) -> IndexSet<String> {
|
2022-08-03 03:51:12 +03:00
|
|
|
retrieve_index_paths_impl(index).unwrap_or_default()
|
2022-06-12 03:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn encode_uri(v: &str) -> String {
|
|
|
|
let parts: Vec<_> = v.split('/').map(urlencoding::encode).collect();
|
|
|
|
parts.join("/")
|
|
|
|
}
|
|
|
|
|
2022-08-23 09:24:42 +03:00
|
|
|
fn retrieve_index_paths_impl(index: &str) -> Option<IndexSet<String>> {
|
2022-06-12 03:43:50 +03:00
|
|
|
let lines: Vec<&str> = index.lines().collect();
|
2022-06-21 18:01:00 +03:00
|
|
|
let line = lines.iter().find(|v| v.contains("DATA ="))?;
|
2022-09-05 05:30:45 +03:00
|
|
|
let line_col = line.find("DATA =").unwrap() + 6;
|
|
|
|
let value: Value = line[line_col..].parse().ok()?;
|
2022-06-12 03:43:50 +03:00
|
|
|
let paths = value
|
|
|
|
.get("paths")?
|
|
|
|
.as_array()?
|
|
|
|
.iter()
|
|
|
|
.flat_map(|v| {
|
|
|
|
let name = v.get("name")?.as_str()?;
|
|
|
|
let path_type = v.get("path_type")?.as_str()?;
|
|
|
|
if path_type.ends_with("Dir") {
|
|
|
|
Some(format!("{}/", name))
|
|
|
|
} else {
|
|
|
|
Some(name.to_owned())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
Some(paths)
|
|
|
|
}
|