about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
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