diff --git a/README.md b/README.md index 468c820..1347556 100644 --- a/README.md +++ b/README.md @@ -129,5 +129,6 @@ it's on the remote, this should prompt an error. - wrap git, do something like `scf clone` that pulls in Git repo. - recursive pulling. + - check no external file; add tests diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..10b35bf Binary files /dev/null and b/logo.png differ diff --git a/src/lib.rs b/src/lib.rs index aa78c23..199aaa8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ pub mod lib { pub mod macros; pub mod remote; pub mod utils; + pub mod test_utilities; } pub mod logging_setup; diff --git a/src/lib/api/figshare.rs b/src/lib/api/figshare.rs index ee60dbe..f73141d 100644 --- a/src/lib/api/figshare.rs +++ b/src/lib/api/figshare.rs @@ -27,14 +27,14 @@ use crate::lib::data::{DataFile, MergedFile}; use crate::lib::remote::{AuthKeys, RemoteFile, DownloadInfo,RequestData}; use crate::lib::project::LocalMetadata; -const BASE_URL: &str = "https://api.figshare.com/v2/"; +pub const FIGSHARE_BASE_URL: &str = "https://api.figshare.com/v2/"; // for testing: const TEST_TOKEN: &str = "test-token"; // for serde deserialize default fn figshare_api_url() -> String { - BASE_URL.to_string() + FIGSHARE_BASE_URL.to_string() } #[derive(Debug, Serialize, Deserialize, PartialEq)] @@ -262,7 +262,7 @@ impl FigShareAPI { auth_keys }; let token = auth_keys.get("figshare".to_string())?; - let base_url = base_url.unwrap_or(BASE_URL.to_string()); + let base_url = base_url.unwrap_or(FIGSHARE_BASE_URL.to_string()); Ok(FigShareAPI { base_url, article_id: None, @@ -275,6 +275,10 @@ impl FigShareAPI { self.token = token; } + pub fn get_base_url(&self) -> String { + self.base_url.clone() + } + async fn issue_request(&self, method: Method, endpoint: &str, data: Option>) -> Result { let mut headers = HeaderMap::new(); diff --git a/src/lib/data.rs b/src/lib/data.rs index 4c36e84..60d7017 100644 --- a/src/lib/data.rs +++ b/src/lib/data.rs @@ -478,7 +478,6 @@ pub struct DataCollection { /// interacting with the data manifest (including remotes). impl DataCollection { pub fn new() -> Self { - Self { files: HashMap::new(), remotes: HashMap::new(), @@ -575,6 +574,9 @@ impl DataCollection { } } + // Register the remote + // + // This can overwrite existing entries. pub fn register_remote(&mut self, dir: &String, remote: Remote) -> Result<()> { self.validate_remote_directory(dir)?; self.remotes.insert(dir.to_string(), remote); @@ -1011,7 +1013,11 @@ impl DataCollection { #[cfg(test)] mod tests { - use super::DataFile; + use crate::lib::api::figshare::{FIGSHARE_BASE_URL,FigShareAPI, self}; + use crate::lib::remote::Remote; + use crate::lib::test_utilities::check_error; + + use super::{DataFile, DataCollection, DataCollectionMetadata}; use std::path::Path; use std::io::Write; use tempfile::NamedTempFile; @@ -1125,6 +1131,24 @@ mod tests { } - // ==== Data Collection Tests + #[test] + fn test_register_remote_figshare() { + let mut dc = DataCollection::new(); + + let dir = "data/supplement".to_string(); + let result = FigShareAPI::new("Test remote", None); + assert!(result.is_ok(), "FigShareAPI::new() resulted in error!"); + let figshare = result.unwrap(); + assert!(figshare.get_base_url() == FIGSHARE_BASE_URL, "FigShareAPI.base_url is not correct!"); + dc.register_remote(&dir, Remote::FigShareAPI(figshare)).unwrap(); + + // check that it's been inserted + assert!(dc.remotes.contains_key(&dir), "Remote not registered!"); + + // Let's check that validate_remote_directory() is working + let figshare = FigShareAPI::new("Another test remote", None).unwrap(); + let result = dc.register_remote(&dir, Remote::FigShareAPI(figshare)); + check_error(result, "already tracked"); + } }