about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-09-26 02:04:27 +0300
committerVika <vika@fireburn.ru>2021-09-26 02:06:56 +0300
commit9203dd3ef7b62489116e7b7fe0b9d288c3389c78 (patch)
treec958b9bd42241b4452262ddfe197b1e91d211cbb /src/lib.rs
parent572435f7c8e1d613983309eca268c3f87ec5f00f (diff)
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.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs50
1 files changed, 45 insertions, 5 deletions
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<String>,
+    internal_token: Option<String>,
+) -> App<database::FileStorage> {
+    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<database::FileStorage>
+) {
+    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::RedisStorage>,
-        database::RedisInstance,
+        database::FileStorage,
+        App<database::FileStorage>,
+        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<database::RedisStorage>,
+        app: &App<database::FileStorage>,
         json: serde_json::Value,
     ) -> surf::Response {
         let request = app