From 610b0a6550c758529cf6c34587f45e483a240df4 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 14 Nov 2018 18:37:38 -0800 Subject: rustfmt --- rust/tests/helpers.rs | 14 ++-- rust/tests/test_api_server_client.rs | 7 +- rust/tests/test_api_server_http.rs | 2 +- rust/tests/test_old_python_tests.rs | 141 ++++++++++++++++++++++++----------- 4 files changed, 105 insertions(+), 59 deletions(-) diff --git a/rust/tests/helpers.rs b/rust/tests/helpers.rs index a5685614..5e182508 100644 --- a/rust/tests/helpers.rs +++ b/rust/tests/helpers.rs @@ -1,26 +1,22 @@ - extern crate diesel; extern crate fatcat; extern crate fatcat_api_spec; -extern crate uuid; extern crate iron; extern crate iron_test; +extern crate uuid; -use std::{thread, time}; use self::iron_test::response; -use iron::{status, Iron, Listening, Headers}; +use fatcat_api_spec::client::Client; use iron::headers::ContentType; use iron::mime::Mime; -use fatcat_api_spec::client::Client; +use iron::{status, Headers, Iron, Listening}; +use std::{thread, time}; // A current problem with this method is that if the test fails (eg, panics, assert fails), the // server never gets closed, and the server thread hangs forever. // One workaround might be to invert the function, take a closure, capture the panic/failure, and // cleanup. -pub fn setup_client() -> ( - Client, - Listening, -) { +pub fn setup_client() -> (Client, Listening) { let server = fatcat::test_server().unwrap(); let router = fatcat_api_spec::router(server); // this is an unfortunate hack for testings seeming to fail in CI diff --git a/rust/tests/test_api_server_client.rs b/rust/tests/test_api_server_client.rs index fb53c295..e4ead507 100644 --- a/rust/tests/test_api_server_client.rs +++ b/rust/tests/test_api_server_client.rs @@ -11,17 +11,16 @@ extern crate fatcat; extern crate fatcat_api_spec; -extern crate uuid; extern crate iron; +extern crate uuid; -use fatcat_api_spec::{Context, Api, ApiNoContext, Future, ContextWrapperExt}; +use fatcat_api_spec::{Api, ApiNoContext, Context, ContextWrapperExt, Future}; mod helpers; -use helpers::{setup_client}; +use helpers::setup_client; #[test] fn test_basic() { - let (client, mut server) = setup_client(); let client = client.with_context(Context::new()); diff --git a/rust/tests/test_api_server_http.rs b/rust/tests/test_api_server_http.rs index f43ee756..6266a747 100644 --- a/rust/tests/test_api_server_http.rs +++ b/rust/tests/test_api_server_http.rs @@ -21,7 +21,7 @@ use iron_test::request; use uuid::Uuid; mod helpers; -use helpers::{setup_http, check_http_response}; +use helpers::{check_http_response, setup_http}; #[test] fn test_entity_gets() { diff --git a/rust/tests/test_old_python_tests.rs b/rust/tests/test_old_python_tests.rs index 91a5a655..6f212e71 100644 --- a/rust/tests/test_old_python_tests.rs +++ b/rust/tests/test_old_python_tests.rs @@ -6,18 +6,17 @@ extern crate fatcat; extern crate fatcat_api_spec; -extern crate uuid; extern crate iron; +extern crate uuid; -use fatcat_api_spec::*; use fatcat_api_spec::models::*; +use fatcat_api_spec::*; mod helpers; -use helpers::{setup_client}; +use helpers::setup_client; #[test] fn test_api_rich_create() { - let (client, mut server) = setup_client(); let client = client.with_context(Context::new()); @@ -28,34 +27,43 @@ fn test_api_rich_create() { let resp = client.create_editgroup(new_eg).wait().unwrap(); let editgroup_id = match resp { CreateEditgroupResponse::SuccessfullyCreated(eg) => eg.id.unwrap(), - _ => unreachable!() + _ => unreachable!(), }; let mut new_container = ContainerEntity::new("schmournal".to_string()); new_container.publisher = Some("society of authors".to_string()); new_container.issnl = Some("2222-3333".to_string()); // extra=dict(a=2, i="zing"))), - let resp = client.create_container(new_container, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_container(new_container, Some(editgroup_id.clone())) + .wait() + .unwrap(); let container_id = match resp { CreateContainerResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_creator = CreatorEntity::new("anon y. mouse".to_string()); new_creator.orcid = Some("0000-0002-1825-0097".to_string()); // extra=dict(a=2, i="zing"))), - let resp = client.create_creator(new_creator, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_creator(new_creator, Some(editgroup_id.clone())) + .wait() + .unwrap(); let creator_id = match resp { CreateCreatorResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let new_work = WorkEntity::new(); // extra=dict(a=2, i="zing"))), - let resp = client.create_work(new_work, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_work(new_work, Some(editgroup_id.clone())) + .wait() + .unwrap(); let work_id = match resp { CreateWorkResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; // this stub work will be referenced @@ -70,10 +78,13 @@ fn test_api_rich_create() { rref.title = Some("some other work".to_string()); new_release.refs = Some(vec![rref]); // extra=dict(a=2, i="zing"))), - let resp = client.create_release(new_release, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let stub_release_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("dummy work".to_string()); @@ -89,10 +100,13 @@ fn test_api_rich_create() { rref.target_release_id = Some(stub_release_id.clone()); new_release.refs = Some(vec![rref]); // extra=dict(f=7, b="loopy"))), - let resp = client.create_release(new_release, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let release_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_file = FileEntity::new(); @@ -100,7 +114,10 @@ fn test_api_rich_create() { new_file.size = Some(1234); new_file.releases = Some(vec![release_id.clone()]); // extra=dict(f=4, b="zing"))), - let resp = client.create_file(new_file, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_file(new_file, Some(editgroup_id.clone())) + .wait() + .unwrap(); let file_id = match resp { CreateFileResponse::CreatedEntity(ee) => ee.ident, _ => { @@ -112,104 +129,138 @@ fn test_api_rich_create() { let resp = client.get_changelog(Some(1)).wait().unwrap(); let last_change_id = match resp { GetChangelogResponse::Success(list) => list[0].index, - _ => unreachable!() + _ => unreachable!(), }; - match client.accept_editgroup(editgroup_id.clone()).wait().unwrap() { + match client + .accept_editgroup(editgroup_id.clone()) + .wait() + .unwrap() + { AcceptEditgroupResponse::MergedSuccessfully(_) => (), - _ => unreachable!() + _ => unreachable!(), }; let resp = client.get_changelog(Some(1)).wait().unwrap(); match resp { - GetChangelogResponse::Success(list) => assert_eq!(list[0].index, last_change_id+1), - _ => unreachable!() + GetChangelogResponse::Success(list) => assert_eq!(list[0].index, last_change_id + 1), + _ => unreachable!(), }; // test that foreign key relations worked let re = match client.get_release(release_id.clone(), None).wait().unwrap() { GetReleaseResponse::FoundEntity(e) => e, - _ => unreachable!() + _ => unreachable!(), }; - assert_eq!(re.contribs.clone().unwrap()[0].clone().creator_id.unwrap(), creator_id); + assert_eq!( + re.contribs.clone().unwrap()[0].clone().creator_id.unwrap(), + creator_id + ); assert_eq!(re.work_id.unwrap(), work_id); - assert_eq!(re.contribs.unwrap()[0].clone().creator_id.unwrap(), creator_id); - assert_eq!(re.refs.unwrap()[0].clone().target_release_id.unwrap(), stub_release_id); + assert_eq!( + re.contribs.unwrap()[0].clone().creator_id.unwrap(), + creator_id + ); + assert_eq!( + re.refs.unwrap()[0].clone().target_release_id.unwrap(), + stub_release_id + ); let fe = match client.get_file(file_id, None).wait().unwrap() { GetFileResponse::FoundEntity(e) => e, - _ => unreachable!() + _ => unreachable!(), }; assert_eq!(fe.releases.unwrap()[0], release_id.clone()); // had a test for active_editgroup here, but that's soon-to-be-deprecated - + server.close().unwrap() } #[test] fn test_merge_works() { - let (client, mut server) = setup_client(); let client = client.with_context(Context::new()); let admin_id = "aaaaaaaaaaaabkvkaaaaaaaaae".to_string(); - let resp = client.create_editgroup(Editgroup::new(admin_id)).wait().unwrap(); + let resp = client + .create_editgroup(Editgroup::new(admin_id)) + .wait() + .unwrap(); let editgroup_id = match resp { CreateEditgroupResponse::SuccessfullyCreated(eg) => eg.id.unwrap(), - _ => unreachable!() + _ => unreachable!(), }; // Create 2x works, each with releases; work_b has two releases - let resp = client.create_work(WorkEntity::new(), Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_work(WorkEntity::new(), Some(editgroup_id.clone())) + .wait() + .unwrap(); let work_a_id = match resp { CreateWorkResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("some release".to_string()); new_release.release_type = Some("journal-article".to_string()); new_release.work_id = Some(work_a_id.clone()); new_release.doi = Some("10.1234/A1".to_string()); - let resp = client.create_release(new_release, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let _release_a1_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; - let resp = client.create_work(WorkEntity::new(), Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_work(WorkEntity::new(), Some(editgroup_id.clone())) + .wait() + .unwrap(); let work_b_id = match resp { CreateWorkResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("some release".to_string()); new_release.release_type = Some("journal-article".to_string()); new_release.work_id = Some(work_b_id.clone()); new_release.doi = Some("10.1234/B1".to_string()); - let resp = client.create_release(new_release, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let _release_b1_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; let mut new_release = ReleaseEntity::new("some release".to_string()); new_release.release_type = Some("journal-article".to_string()); new_release.work_id = Some(work_b_id.clone()); new_release.doi = Some("10.1234/B2".to_string()); - let resp = client.create_release(new_release, Some(editgroup_id.clone())).wait().unwrap(); + let resp = client + .create_release(new_release, Some(editgroup_id.clone())) + .wait() + .unwrap(); let _release_b2_id = match resp { CreateReleaseResponse::CreatedEntity(ee) => ee.ident, - _ => unreachable!() + _ => unreachable!(), }; - match client.accept_editgroup(editgroup_id.clone()).wait().unwrap() { + match client + .accept_editgroup(editgroup_id.clone()) + .wait() + .unwrap() + { AcceptEditgroupResponse::MergedSuccessfully(_) => (), - _ => unreachable!() + _ => unreachable!(), }; -/* TODO: + /* TODO: // merge works client.merge_works(work_a_id, work_b_id) */ @@ -217,11 +268,11 @@ fn test_merge_works() { // check results let work_a = match client.get_work(work_a_id.clone(), None).wait().unwrap() { GetWorkResponse::FoundEntity(e) => e, - _ => unreachable!() + _ => unreachable!(), }; let _work_b = match client.get_work(work_b_id.clone(), None).wait().unwrap() { GetWorkResponse::FoundEntity(e) => e, - _ => unreachable!() + _ => unreachable!(), }; // TODO: assert_eq!(work_a.revision.unwrap(), work_b.revision.unwrap()); assert_eq!(work_a.redirect, None); -- cgit v1.2.3