From 27b33c13ba8cc7c4980abde2cf4a4331396376df Mon Sep 17 00:00:00 2001 From: jakka Date: Fri, 17 Oct 2025 17:08:43 +0300 Subject: various fixes reorganized project structure so client tests are not in the libraries changed some types on functions for better use --- tests/async.rs | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/sync.rs | 33 +++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 tests/async.rs create mode 100644 tests/sync.rs (limited to 'tests') diff --git a/tests/async.rs b/tests/async.rs new file mode 100644 index 0000000..1eddef1 --- /dev/null +++ b/tests/async.rs @@ -0,0 +1,91 @@ +use hydrus_api_rs::async_lib::{client::*, traits::*}; +use hydrus_api_rs::types::*; +use std::path::PathBuf; + +fn init_client() -> HydrusClient { + let keyfile = PathBuf::from("secrets"); + let key = std::fs::read_to_string(keyfile).unwrap().trim().to_string(); + let mut client: HydrusClient = HydrusClient::new("http://127.0.0.1:45869/"); + client.set_api_key(key); + client +} + +#[tokio::test] +async fn test_service_name_info() { + let client = init_client(); + let _ = client.get_service_name("all my files").await.unwrap(); +} + +#[tokio::test] +async fn test_service_key_info() { + let client = init_client(); + let _ = client + .get_service_key("616c6c206c6f63616c206d65646961") + .await + .unwrap(); +} + +#[tokio::test] +async fn test_get_services() { + let client = init_client(); + let res = client.get_services().await.unwrap(); + assert!(!res.is_empty()) +} + +#[tokio::test] +async fn add_and_delete_file() { + let client = init_client(); + let path = PathBuf::from("./assets/img.png").canonicalize().unwrap(); + let file = client + .add_file_via_path(path.clone(), None, None) + .await + .unwrap(); + if client + .add_file_via_path(path.clone(), None, None) + .await + .unwrap() + .status + != AddFileStatus::AlreadyInDatabase + { + panic!(); + } + + let trash_service = Some(FileDomain::FileServiceKey( + client + .get_service_name("all my files") + .await + .unwrap() + .service_key, + )); + + client + .delete_files(HydrusFile::Hash(file.hash.clone()), None, None) + .await + .unwrap(); + client + .delete_files(HydrusFile::Hash(file.hash.clone()), trash_service, None) + .await + .unwrap(); + + client + .clear_file_deletion_records(HydrusFile::Hash(file.hash)) + .await + .unwrap(); + let file = client.add_file_via_file(path.clone()).await.unwrap(); + if client.add_file_via_file(path).await.unwrap().status != AddFileStatus::AlreadyInDatabase { + panic!(); + } + client + .delete_files(HydrusFile::Hash(file.hash.clone()), None, None) + .await + .unwrap(); + client + .delete_files(HydrusFile::Hash(file.hash.clone()), None, None) + .await + .unwrap(); + + client + .clear_file_deletion_records(HydrusFile::Hash(file.hash)) + .await + .unwrap(); +} diff --git a/tests/sync.rs b/tests/sync.rs new file mode 100644 index 0000000..b37b9db --- /dev/null +++ b/tests/sync.rs @@ -0,0 +1,33 @@ +use hydrus_api_rs::sync_lib::client::HydrusClient; +use hydrus_api_rs::sync_lib::traits::*; +use std::path::PathBuf; + +#[test] +fn test_service_name_info() { + let keyfile = PathBuf::from("secrets"); + let key = std::fs::read_to_string(keyfile).unwrap().trim().to_string(); + let mut client: HydrusClient = HydrusClient::new("http://127.0.0.1:45869/"); + client.set_api_key(key); + let _ = client.get_service_name("all my files").unwrap(); +} + +#[test] +fn test_service_key_info() { + let keyfile = PathBuf::from("secrets"); + let mut client: HydrusClient = HydrusClient::new("http://127.0.0.1:45869/"); + let key = std::fs::read_to_string(keyfile).unwrap().trim().to_string(); + client.set_api_key(key); + let _ = client + .get_service_key("616c6c206c6f63616c206d65646961") + .unwrap(); +} + +#[test] +fn test_get_services() { + let mut client: HydrusClient = HydrusClient::new("http://127.0.0.1:45869/"); + let keyfile = PathBuf::from("secrets"); + let key = std::fs::read_to_string(keyfile).unwrap().trim().to_string(); + client.set_api_key(key); + let res = client.get_services().unwrap(); + assert!(!res.is_empty()) +} -- cgit v1.3.1