mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-27 03:21:49 +03:00
Fix build
This commit is contained in:
parent
cde9c0ef40
commit
3f30543d50
@ -54,7 +54,7 @@ impl LoginCommand {
|
||||
impl CLI for LoginCommand {
|
||||
// Format: token, username, password
|
||||
type Options = (Option<String>, Option<String>, Option<String>);
|
||||
type Output = ();
|
||||
type Output = String;
|
||||
|
||||
const ABOUT: AboutType = "Login to the package manager (*)";
|
||||
const ARGUMENTS: &'static [ArgumentType] = &[
|
||||
@ -138,6 +138,101 @@ impl CLI for LoginCommand {
|
||||
|
||||
LoginCommand::write_token(token.as_str())?;
|
||||
log::info!("Successfully logged in");
|
||||
Ok(token)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
use std::{
|
||||
fs::{remove_dir, remove_file},
|
||||
io,
|
||||
};
|
||||
|
||||
const TEST_DIR: &str = ".test";
|
||||
|
||||
fn setup(suffix: &str) -> Result<(), io::Error> {
|
||||
let test_dir = format!("{}_{}", TEST_DIR, suffix);
|
||||
create_dir(&test_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_credential_dir_exists() -> Result<(), io::Error> {
|
||||
let suffix = "test1";
|
||||
setup(suffix)?;
|
||||
create_dir(LEO_CREDENTIALS_DIR)?;
|
||||
|
||||
let token = "SOME_TOKEN".to_string();
|
||||
let options = (Some(token.clone()), None, None);
|
||||
LoginCommand::output(options).unwrap();
|
||||
|
||||
assert_eq!(token, LoginCommand::read_token()?);
|
||||
clean(suffix)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_credential_file_exists() -> Result<(), io::Error> {
|
||||
let suffix = "test2";
|
||||
setup(suffix)?;
|
||||
create_dir(LEO_CREDENTIALS_DIR)?;
|
||||
let old_token = "OLD_TOKEN";
|
||||
LoginCommand::write_token(old_token)?;
|
||||
|
||||
let token = "NEW_TOKEN".to_string();
|
||||
let options = (Some(token.clone()), None, None);
|
||||
LoginCommand::output(options).unwrap();
|
||||
|
||||
assert_eq!(token, LoginCommand::read_token()?);
|
||||
clean(suffix)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_credential_dir_does_not_exist() -> Result<(), io::Error> {
|
||||
let suffix = "test3";
|
||||
setup(suffix)?;
|
||||
|
||||
let token = "SOME_TOKEN".to_string();
|
||||
let options = (Some(token.clone()), None, None);
|
||||
LoginCommand::output(options).unwrap();
|
||||
|
||||
assert_eq!(token, LoginCommand::read_token()?);
|
||||
clean(suffix)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_credential_file_does_not_exist() -> Result<(), io::Error> {
|
||||
let suffix = "test4";
|
||||
setup(suffix)?;
|
||||
create_dir(LEO_CREDENTIALS_DIR)?;
|
||||
|
||||
let token = "SOME_TOKEN".to_string();
|
||||
let options = (Some(token.clone()), None, None);
|
||||
LoginCommand::output(options).unwrap();
|
||||
|
||||
assert_eq!(token, LoginCommand::read_token()?);
|
||||
clean(suffix)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user