test: add /api/hier test
This commit is contained in:
parent
0b2c0adf59
commit
bca29fa542
1 changed files with 52 additions and 0 deletions
|
@ -970,6 +970,56 @@ mod tests {
|
||||||
assert!(!info.desktop);
|
assert!(!info.desktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_web::test]
|
||||||
|
async fn test_get_hier() {
|
||||||
|
let app = actix_web::test::init_service(crate::serve::get_app::<
|
||||||
|
std::path::PathBuf,
|
||||||
|
Vec<String>,
|
||||||
|
>(None, vec![], get_state()))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let req = actix_web::test::TestRequest::get()
|
||||||
|
.uri("/api/hier/")
|
||||||
|
.to_request();
|
||||||
|
|
||||||
|
let result = actix_web::test::call_service(&app, req).await;
|
||||||
|
assert_eq!(result.status(), http::StatusCode::MOVED_PERMANENTLY);
|
||||||
|
assert_eq!(
|
||||||
|
result
|
||||||
|
.headers()
|
||||||
|
.get(http::header::LOCATION)
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
"../../api/hier_roots"
|
||||||
|
);
|
||||||
|
|
||||||
|
let req = actix_web::test::TestRequest::get()
|
||||||
|
.uri("/api/hier_roots")
|
||||||
|
.to_request();
|
||||||
|
let roots: HashMap<String, Entry> =
|
||||||
|
actix_web::test::call_and_read_body_json(&app, req).await;
|
||||||
|
|
||||||
|
let mut labels = roots.values().filter(|v| v.attribute == LABEL_ATTR);
|
||||||
|
assert_eq!(labels.next().unwrap().value, "NATIVE".into());
|
||||||
|
assert!(labels.next().is_none());
|
||||||
|
|
||||||
|
let req = actix_web::test::TestRequest::get()
|
||||||
|
.uri("/api/hier/NATIVE/hello-world.txt")
|
||||||
|
.to_request();
|
||||||
|
let result = actix_web::test::call_service(&app, req).await;
|
||||||
|
assert_eq!(result.status(), http::StatusCode::FOUND);
|
||||||
|
assert_eq!(
|
||||||
|
result
|
||||||
|
.headers()
|
||||||
|
.get(http::header::LOCATION)
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
"../../api/obj/zQmbuQbmm7z1AeZjbBw2iX1557ZoUFQ8vrMKaaw2UYrt5zG"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn get_state() -> State {
|
fn get_state() -> State {
|
||||||
// Prepare temporary filesystem structure
|
// Prepare temporary filesystem structure
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
@ -994,6 +1044,8 @@ mod tests {
|
||||||
) as Box<dyn UpStore + Send + Sync>);
|
) as Box<dyn UpStore + Send + Sync>);
|
||||||
let job_container = jobs::JobContainer::new();
|
let job_container = jobs::JobContainer::new();
|
||||||
|
|
||||||
|
store.update(&upend, job_container.clone(), true).unwrap();
|
||||||
|
|
||||||
State {
|
State {
|
||||||
upend,
|
upend,
|
||||||
store,
|
store,
|
||||||
|
|
Loading…
Reference in a new issue