mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-21 08:31:33 +03:00
Format code
This commit is contained in:
parent
2ccbf2eafe
commit
707168de0a
@ -63,92 +63,110 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
|
||||||
fs::{remove_dir, remove_file},
|
fs::{remove_dir, remove_file},
|
||||||
io,
|
io,
|
||||||
};
|
};
|
||||||
|
|
||||||
const TEST_DIR: &str = ".test";
|
const TEST_DIR: &str = ".test";
|
||||||
|
|
||||||
fn setup() -> Result<(), io::Error> {
|
fn setup(suffix: &str) -> Result<(), io::Error> {
|
||||||
create_dir(TEST_DIR)?;
|
let test_dir = format!("{}_{}", TEST_DIR, suffix);
|
||||||
env::set_current_dir(TEST_DIR)?;
|
create_dir(&test_dir)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clean() -> Result<(), io::Error> {
|
fn clean(suffix: &str) -> Result<(), io::Error> {
|
||||||
remove_file(&format!("{}/{}", LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE))?;
|
let test_dir = format!("{}_{}", TEST_DIR, suffix);
|
||||||
remove_dir(LEO_CREDENTIALS_DIR)?;
|
remove_file(&format!(
|
||||||
env::set_current_dir("../")?;
|
"{}/{}/{}",
|
||||||
remove_dir(TEST_DIR)?;
|
test_dir, LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE
|
||||||
|
))?;
|
||||||
|
remove_dir(&format!("{}/{}", test_dir, LEO_CREDENTIALS_DIR))?;
|
||||||
|
remove_dir(test_dir)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_token() -> Result<String, io::Error> {
|
fn get_token(suffix: &str) -> Result<String, io::Error> {
|
||||||
let mut credentials = File::open(&format!("{}/{}", LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE))?;
|
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();
|
let mut buf = String::new();
|
||||||
credentials.read_to_string(&mut buf)?;
|
credentials.read_to_string(&mut buf)?;
|
||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_token(token: &str) -> Result<(), io::Error> {
|
fn create_token(suffix: &str, token: &str) -> Result<(), io::Error> {
|
||||||
let mut f = File::create(&format!("{}/{}", LEO_CREDENTIALS_DIR, LEO_CREDENTIALS_FILE))?;
|
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())?;
|
f.write_all(token.as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_credential_dir_exists() -> Result<(), io::Error> {
|
fn test_credential_dir_exists() -> Result<(), io::Error> {
|
||||||
setup()?;
|
let suffix = "test1";
|
||||||
|
setup(suffix)?;
|
||||||
create_dir(LEO_CREDENTIALS_DIR)?;
|
create_dir(LEO_CREDENTIALS_DIR)?;
|
||||||
|
|
||||||
let token = "SOME_TOKEN".to_string();
|
let token = "SOME_TOKEN".to_string();
|
||||||
let options = Some(token.clone());
|
let options = Some(token.clone());
|
||||||
LoginCommand::output(options).unwrap();
|
LoginCommand::output(options).unwrap();
|
||||||
assert_eq!(token, get_token()?);
|
assert_eq!(token, get_token(suffix)?);
|
||||||
clean()?;
|
clean(suffix)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_credential_file_exists() -> Result<(), io::Error> {
|
fn test_credential_file_exists() -> Result<(), io::Error> {
|
||||||
setup()?;
|
let suffix = "test2";
|
||||||
|
setup(suffix)?;
|
||||||
create_dir(LEO_CREDENTIALS_DIR)?;
|
create_dir(LEO_CREDENTIALS_DIR)?;
|
||||||
create_token("OLD_TOKEN")?;
|
create_token(suffix, "OLD_TOKEN")?;
|
||||||
|
|
||||||
let token = "NEW_TOKEN".to_string();
|
let token = "NEW_TOKEN".to_string();
|
||||||
let options = Some(token.clone());
|
let options = Some(token.clone());
|
||||||
LoginCommand::output(options).unwrap();
|
LoginCommand::output(options).unwrap();
|
||||||
|
|
||||||
assert_eq!(token, get_token()?);
|
assert_eq!(token, get_token(suffix)?);
|
||||||
clean()?;
|
clean(suffix)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_credential_dir_does_not_exist() -> Result<(), io::Error> {
|
fn test_credential_dir_does_not_exist() -> Result<(), io::Error> {
|
||||||
setup()?;
|
let suffix = "test3";
|
||||||
|
setup(suffix)?;
|
||||||
|
|
||||||
let token = "SOME_TOKEN".to_string();
|
let token = "SOME_TOKEN".to_string();
|
||||||
let options = Some(token.clone());
|
let options = Some(token.clone());
|
||||||
LoginCommand::output(options).unwrap();
|
LoginCommand::output(options).unwrap();
|
||||||
|
|
||||||
assert_eq!(token, get_token()?);
|
assert_eq!(token, get_token(suffix)?);
|
||||||
clean()?;
|
clean(suffix)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_credential_file_does_not_exist() -> Result<(), io::Error> {
|
fn test_credential_file_does_not_exist() -> Result<(), io::Error> {
|
||||||
setup()?;
|
let suffix = "test4";
|
||||||
|
setup(suffix)?;
|
||||||
create_dir(LEO_CREDENTIALS_DIR)?;
|
create_dir(LEO_CREDENTIALS_DIR)?;
|
||||||
|
|
||||||
let token = "SOME_TOKEN".to_string();
|
let token = "SOME_TOKEN".to_string();
|
||||||
let options = Some(token.clone());
|
let options = Some(token.clone());
|
||||||
LoginCommand::output(options).unwrap();
|
LoginCommand::output(options).unwrap();
|
||||||
|
|
||||||
assert_eq!(token, get_token()?);
|
assert_eq!(token, get_token(suffix)?);
|
||||||
clean()?;
|
clean(suffix)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user