1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
use super::command::{Command, Query}; use super::command::Command::LogReopen; use std::collections::HashMap; use command_query::CommandQuery; use queryable::Queryable; use command_line::CommandLine; use commandable::Commandable; use request_cancellable::RequestCancellable; use request_timeoutable::RequestTimeoutable; #[derive(Clone, PartialEq, Eq, Debug)] pub struct LogReopenCommand { command: Command, arguments: HashMap<String, String>, } impl Default for LogReopenCommand { fn default() -> LogReopenCommand { LogReopenCommand { command: LogReopen, arguments: HashMap::new(), } } } impl LogReopenCommand { pub fn new() -> LogReopenCommand { Default::default() } pub fn build(self) -> (Command, Query) { let mut query: Query = vec![]; for (key, value) in &self.arguments { query.push((key.to_owned(), value.to_owned())); } (self.command, query) } } impl Queryable for LogReopenCommand { fn to_query(self) -> String { let (command, query) = self.build(); let mut command = CommandQuery::new(command, query); command.encode() } } impl Commandable for LogReopenCommand { fn to_command(self) -> String { let (command, query) = self.build(); let mut command = CommandLine::new(command, query); command.encode() } } request_cancellable!(LogReopenCommand); request_timeoutable!(LogReopenCommand); #[cfg(test)] mod test { use super::*; use std::collections::HashMap; use command::Command::LogReopen; use queryable::Queryable; use commandable::Commandable; #[test] fn test_new() { let log_reopen = LogReopenCommand::new(); let expected = LogReopenCommand { command: LogReopen, arguments: HashMap::new(), }; assert_eq!(expected, log_reopen); } #[test] fn test_build() { let actual = LogReopenCommand::new().build(); let expected = (LogReopen, vec![]); assert_eq!(expected, actual); } #[test] fn test_queryable() { let query = LogReopenCommand::new().to_query(); let url_encoded = "/d/log_reopen?"; assert_eq!(url_encoded.to_string(), query); } #[test] fn test_commandable() { let query = LogReopenCommand::new().to_command(); let cli_encoded = "log_reopen"; assert_eq!(cli_encoded.to_string(), query); } }