Skip to content

Commit

Permalink
Test login prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 20, 2022
1 parent c5af465 commit b37c79e
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/cli/src/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ impl Login {
}
_ => "Please paste the login token".to_string(),
};
Input::new().with_prompt(&login_prompt).interact_text()
#[cfg(test)]
{
Ok(login_prompt)
}
#[cfg(not(test))]
{
Input::new().with_prompt(&login_prompt).interact_text()
}
}
}
}
Expand All @@ -47,3 +54,23 @@ impl Login {
.map_err(|e| anyhow::anyhow!("{e}"))
}
}

#[test]
fn test_login_2() {
let login = Login {
registry: "wapm.dev".to_string(),
token: None,
};

assert_eq!(
login.get_token_or_ask_user().unwrap(),
"Please paste the login token for https://wapm.dev/me"
);

let login = Login {
registry: "wapm.dev".to_string(),
token: Some("abc".to_string()),
};

assert_eq!(login.get_token_or_ask_user().unwrap(), "abc");
}

0 comments on commit b37c79e

Please sign in to comment.