From 9203dd3ef7b62489116e7b7fe0b9d288c3389c78 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 26 Sep 2021 02:04:27 +0300 Subject: Moved integration tests and allowed the binary to use file backend Now the Redis dependencies are optional and only required if you want to test the backend or actually use it in production. The app displays a hint if you try to launch with an unsupported backend. --- src/lib.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 77a6c11..1c6394a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,6 +67,7 @@ where app } +#[cfg(redis)] pub async fn get_app_with_redis( token_endpoint: surf::Url, authorization_endpoint: surf::Url, @@ -86,7 +87,46 @@ pub async fn get_app_with_redis( equip_app(app) } +pub async fn get_app_with_file( + token_endpoint: surf::Url, + authorization_endpoint: surf::Url, + backend_uri: String, + media_endpoint: Option, + internal_token: Option, +) -> App { + let app = tide::with_state(ApplicationState { + token_endpoint, + media_endpoint, + authorization_endpoint, + internal_token, + storage: database::FileStorage::new(todo!()).await.unwrap(), + http_client: surf::Client::new(), + }); + + equip_app(app) +} + #[cfg(test)] +pub async fn get_app_with_test_file(token_endpoint: surf::Url) -> ( + tempdir::TempDir, + database::FileStorage, + App +) { + use surf::Url; + let tempdir = tempdir::TempDir::new("file").expect("Failed to create tempdir"); + let backend = database::FileStorage::new(tempdir.path().to_path_buf()).await.unwrap(); + let app = tide::with_state(ApplicationState { + token_endpoint, + media_endpoint: None, + authorization_endpoint: Url::parse("https://indieauth.com/auth").unwrap(), + storage: backend.clone(), + internal_token: None, + http_client: surf::Client::new() + }); + (tempdir, backend, equip_app(app)) +} + +#[cfg(all(redis, test))] pub async fn get_app_with_test_redis( token_endpoint: surf::Url, ) -> ( @@ -122,18 +162,18 @@ mod tests { // Helpers async fn create_app() -> ( - database::RedisStorage, - App, - database::RedisInstance, + database::FileStorage, + App, + tempdir::TempDir, ) { //get_app_with_memory_for_testing(surf::Url::parse(&*mockito::server_url()).unwrap()).await let (r, b, a) = - get_app_with_test_redis(surf::Url::parse(&*mockito::server_url()).unwrap()).await; + get_app_with_test_file(surf::Url::parse(&*mockito::server_url()).unwrap()).await; (b, a, r) } async fn post_json( - app: &App, + app: &App, json: serde_json::Value, ) -> surf::Response { let request = app -- cgit 1.4.1