Add file adding/deleting/archiving functions
Signed-off-by: trivernis <trivernis@protonmail.com>pull/2/head
parent
9fe17d4c90
commit
968156aa7d
@ -0,0 +1,56 @@
|
|||||||
|
use crate::paths::common::BasicHashList;
|
||||||
|
use crate::paths::Path;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct AddFileRequest {
|
||||||
|
pub path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct AddFileResponse {
|
||||||
|
pub status: u8,
|
||||||
|
pub hash: String,
|
||||||
|
pub note: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Path for AddFileResponse {
|
||||||
|
fn get_path() -> String {
|
||||||
|
String::from("add_files/add_file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type DeleteFilesRequest = BasicHashList;
|
||||||
|
pub struct DeleteFilesResponse;
|
||||||
|
|
||||||
|
impl Path for DeleteFilesResponse {
|
||||||
|
fn get_path() -> String {
|
||||||
|
String::from("add_files/delete_files")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type UndeleteFilesRequest = BasicHashList;
|
||||||
|
pub struct UndeleteFilesResponse;
|
||||||
|
|
||||||
|
impl Path for UndeleteFilesResponse {
|
||||||
|
fn get_path() -> String {
|
||||||
|
String::from("add_files/undelete_files")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type ArchiveFilesRequest = BasicHashList;
|
||||||
|
pub struct ArchiveFilesResponse;
|
||||||
|
|
||||||
|
impl Path for ArchiveFilesResponse {
|
||||||
|
fn get_path() -> String {
|
||||||
|
String::from("add_files/archive_files")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type UnarchiveFilesRequest = BasicHashList;
|
||||||
|
pub struct UnarchiveFilesResponse;
|
||||||
|
|
||||||
|
impl Path for UnarchiveFilesResponse {
|
||||||
|
fn get_path() -> String {
|
||||||
|
String::from("add_files/unarchive_files")
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,23 @@
|
|||||||
use hydrus_api::client::Client;
|
use hydrus_api::client::Client;
|
||||||
|
use log::LevelFilter;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub fn setup() {
|
||||||
|
lazy_static::lazy_static! { static ref SETUP_DONE: Arc<AtomicBool> = Arc::new(AtomicBool::new(false)); }
|
||||||
|
if !SETUP_DONE.swap(true, Ordering::SeqCst) {
|
||||||
|
env_logger::builder()
|
||||||
|
.filter_level(LevelFilter::Trace)
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_client() -> Client {
|
pub fn get_client() -> Client {
|
||||||
Client::new(env::var("HYDRUS_URL").unwrap(), env::var("HYDRUS_ACCESS_KEY").unwrap()).unwrap()
|
setup();
|
||||||
|
Client::new(
|
||||||
|
env::var("HYDRUS_URL").unwrap(),
|
||||||
|
env::var("HYDRUS_ACCESS_KEY").unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
mod common;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_adds_files() {
|
||||||
|
let mut client = common::get_client();
|
||||||
|
let result = client.add_file("/does/not/exist").await;
|
||||||
|
assert!(result.is_err()); // because the path does not exist
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_adds_binary_files() {
|
||||||
|
let mut client = common::get_client();
|
||||||
|
let result = client
|
||||||
|
.add_binary_file(vec![0u8, 0u8, 0u8, 0u8])
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(result.status, 4); // should fail because the filetype is unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_deletes_files() {
|
||||||
|
let mut client = common::get_client();
|
||||||
|
client.delete_files(vec![]).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_undeletes_files() {
|
||||||
|
let mut client = common::get_client();
|
||||||
|
client.undelete_files(vec![]).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_archives_files() {
|
||||||
|
let mut client = common::get_client();
|
||||||
|
client.archive_files(vec![]).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_unarchives_files() {
|
||||||
|
let mut client = common::get_client();
|
||||||
|
client.unarchive_files(vec![]).await.unwrap();
|
||||||
|
}
|
Loading…
Reference in New Issue