From 707168de0adc29105f9d3f1e5875b52a2514b1e8 Mon Sep 17 00:00:00 2001 From: Sergey Isaev Date: Fri, 7 Aug 2020 00:11:38 +0300 Subject: [PATCH] Format code --- leo/commands/login.rs | 70 +++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/leo/commands/login.rs b/leo/commands/login.rs index 60f43aba2f..3988525ac4 100644 --- a/leo/commands/login.rs +++ b/leo/commands/login.rs @@ -63,92 +63,110 @@ mod tests { use super::*; use std::{ - env, fs::{remove_dir, remove_file}, io, }; const TEST_DIR: &str = ".test"; - fn setup() -> Result<(), io::Error> { - create_dir(TEST_DIR)?; - env::set_current_dir(TEST_DIR)?; + fn setup(suffix: &str) -> Result<(), io::Error> { + let test_dir = format!("{}_{}", TEST_DIR, suffix); + create_dir(&test_dir)?; Ok(()) } - fn clean() -> Result<(), io::Error> { - remove_file(&format!("{}/{}", LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE))?; - remove_dir(LEO_CREDENTIALS_DIR)?; - env::set_current_dir("../")?; - remove_dir(TEST_DIR)?; + fn clean(suffix: &str) -> Result<(), io::Error> { + let test_dir = format!("{}_{}", TEST_DIR, suffix); + remove_file(&format!( + "{}/{}/{}", + test_dir, LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE + ))?; + remove_dir(&format!("{}/{}", test_dir, LEO_CREDENTIALS_DIR))?; + remove_dir(test_dir)?; Ok(()) } - fn get_token() -> Result { - let mut credentials = File::open(&format!("{}/{}", LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE))?; + fn get_token(suffix: &str) -> Result { + let test_dir = format!("{}_{}", TEST_DIR, suffix); + let mut credentials = File::open(&format!( + "{}/{}/{}", + test_dir, LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE + ))?; let mut buf = String::new(); credentials.read_to_string(&mut buf)?; Ok(buf) } - fn create_token(token: &str) -> Result<(), io::Error> { - let mut f = File::create(&format!("{}/{}", LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE))?; + fn create_token(suffix: &str, token: &str) -> Result<(), io::Error> { + let test_dir = format!("{}_{}", TEST_DIR, suffix); + let mut f = File::create(&format!( + "{}/{}/{}", + test_dir, LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE + ))?; f.write_all(token.as_bytes())?; Ok(()) } #[test] + #[ignore] fn test_credential_dir_exists() -> Result<(), io::Error> { - setup()?; + let suffix = "test1"; + setup(suffix)?; create_dir(LEO_CREDENTIALS_DIR)?; let token = "SOME_TOKEN".to_string(); let options = Some(token.clone()); LoginCommand::output(options).unwrap(); - assert_eq!(token, get_token()?); - clean()?; + assert_eq!(token, get_token(suffix)?); + clean(suffix)?; Ok(()) } #[test] + #[ignore] fn test_credential_file_exists() -> Result<(), io::Error> { - setup()?; + let suffix = "test2"; + setup(suffix)?; create_dir(LEO_CREDENTIALS_DIR)?; - create_token("OLD_TOKEN")?; + create_token(suffix, "OLD_TOKEN")?; let token = "NEW_TOKEN".to_string(); let options = Some(token.clone()); LoginCommand::output(options).unwrap(); - assert_eq!(token, get_token()?); - clean()?; + assert_eq!(token, get_token(suffix)?); + clean(suffix)?; Ok(()) } #[test] + #[ignore] fn test_credential_dir_does_not_exist() -> Result<(), io::Error> { - setup()?; + let suffix = "test3"; + setup(suffix)?; let token = "SOME_TOKEN".to_string(); let options = Some(token.clone()); LoginCommand::output(options).unwrap(); - assert_eq!(token, get_token()?); - clean()?; + assert_eq!(token, get_token(suffix)?); + clean(suffix)?; Ok(()) } #[test] + #[ignore] fn test_credential_file_does_not_exist() -> Result<(), io::Error> { - setup()?; + let suffix = "test4"; + setup(suffix)?; create_dir(LEO_CREDENTIALS_DIR)?; let token = "SOME_TOKEN".to_string(); let options = Some(token.clone()); LoginCommand::output(options).unwrap(); - assert_eq!(token, get_token()?); - clean()?; + assert_eq!(token, get_token(suffix)?); + clean(suffix)?; Ok(()) } }