use crate::configuration::Configuration; use crate::remote::add; use std::io::{Error, ErrorKind::Other, Result}; pub struct AddRemote; impl AddRemote { pub fn new() -> Self { AddRemote } } impl super::Command for AddRemote { fn before_dependencies(&self) -> Vec> { vec![] } fn execute( &self, input: Option<&String>, configuration: &Configuration, _: &str, ) -> Result<()> { let input = input .ok_or_else(|| Error::new(Other, "You must provide a location for the remote."))?; add( &configuration.config_directory, &configuration.remote_config, input, ) } fn after_dependencies(&self) -> Vec> { vec![] } fn command(&self) -> &'static str { "add-remote" } fn help(&self) -> &'static str { "\t\tAdds or updates a git remote to sync with" } } #[cfg(test)] mod tests { use super::*; use crate::command::Command; use crate::configuration::Configuration; use test_utilities::*; #[test] fn test_add_remote_command() { let add_remote = AddRemote::new(); // Create all directories let test_dir = setup_test_dir(); let remote_config = test_dir.join("blogremote"); assert!(!remote_config.exists()); let mut configuration = Configuration::new(); configuration.config_directory = test_dir.clone(); configuration.remote_config = remote_config.clone(); add_remote .execute(Some(&"beep".to_string()), &configuration, "add_remote") .expect("Could not call add_remote"); assert_file_contents(&remote_config, "beep"); cleanup_test_dir(&test_dir); } #[test] fn test_fails_if_no_remote_sent() { let add_remote = AddRemote::new(); let configuration = Configuration::new(); let result = add_remote.execute(None, &configuration, "add_remote"); assert!(result.is_err()); } #[test] fn add_remote_before_dependencies() { let add_remote = AddRemote::new(); let dependencies = add_remote.before_dependencies(); assert_eq!(dependencies.len(), 0); } #[test] fn add_remote_after_dependencies() { let add_remote = AddRemote::new(); let dependencies = add_remote.after_dependencies(); assert_eq!(dependencies.len(), 0); } // These two tests feel pointless but I'm doing it for the coverage :p #[test] fn add_remote_command_output() { let add_remote = AddRemote::new(); add_remote.command(); } #[test] fn add_remote_help_output() { let add_remote = AddRemote::new(); add_remote.help(); } }