mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 21:57:41 +00:00
test: allow running tests as root (#2571)
This commit is contained in:
parent
6817e7f698
commit
436eb61efd
@ -514,6 +514,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn directory_in_root() {
|
||||
let actual = ModuleRenderer::new("directory").path("/etc").collect();
|
||||
let expected = Some(format!(
|
||||
|
@ -86,7 +86,6 @@ fn is_ssh_session(context: &Context) -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::test::ModuleRenderer;
|
||||
use ansi_term::Color;
|
||||
|
||||
// TODO: Add tests for if root user (UID == 0)
|
||||
// Requires mocking
|
||||
@ -100,6 +99,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn no_logname_env_variable() {
|
||||
let actual = ModuleRenderer::new("username")
|
||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||
@ -110,6 +110,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn logname_equals_user() {
|
||||
let actual = ModuleRenderer::new("username")
|
||||
.env("LOGNAME", "astronaut")
|
||||
@ -136,10 +137,16 @@ mod tests {
|
||||
let actual = ModuleRenderer::new("username")
|
||||
.env("LOGNAME", "astronaut")
|
||||
.env(super::USERNAME_ENV_VAR, "cosmonaut")
|
||||
// Test output should not change when run by root/non-root user
|
||||
.config(toml::toml! {
|
||||
[username]
|
||||
style_root = ""
|
||||
style_user = ""
|
||||
})
|
||||
.collect();
|
||||
let expected = Some(format!("{} in ", Color::Yellow.bold().paint("cosmonaut")));
|
||||
let expected = Some("cosmonaut in ");
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(expected, actual.as_deref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -147,10 +154,16 @@ mod tests {
|
||||
let actual = ModuleRenderer::new("username")
|
||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||
.env("SSH_CONNECTION", "192.168.223.17 36673 192.168.223.229 22")
|
||||
// Test output should not change when run by root/non-root user
|
||||
.config(toml::toml! {
|
||||
[username]
|
||||
style_root = ""
|
||||
style_user = ""
|
||||
})
|
||||
.collect();
|
||||
let expected = Some(format!("{} in ", Color::Yellow.bold().paint("astronaut")));
|
||||
let expected = Some("astronaut in ");
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(expected, actual.as_deref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -158,10 +171,16 @@ mod tests {
|
||||
let actual = ModuleRenderer::new("username")
|
||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||
.env("SSH_TTY", "/dev/pts/0")
|
||||
// Test output should not change when run by root/non-root user
|
||||
.config(toml::toml! {
|
||||
[username]
|
||||
style_root = ""
|
||||
style_user = ""
|
||||
})
|
||||
.collect();
|
||||
let expected = Some(format!("{} in ", Color::Yellow.bold().paint("astronaut")));
|
||||
let expected = Some("astronaut in ");
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(expected, actual.as_deref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -169,23 +188,33 @@ mod tests {
|
||||
let actual = ModuleRenderer::new("username")
|
||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||
.env("SSH_CLIENT", "192.168.0.101 39323 22")
|
||||
// Test output should not change when run by root/non-root user
|
||||
.config(toml::toml! {
|
||||
[username]
|
||||
style_root = ""
|
||||
style_user = ""
|
||||
})
|
||||
.collect();
|
||||
let expected = Some(format!("{} in ", Color::Yellow.bold().paint("astronaut")));
|
||||
let expected = Some("astronaut in ");
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(expected, actual.as_deref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_always() {
|
||||
let actual = ModuleRenderer::new("username")
|
||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||
// Test output should not change when run by root/non-root user
|
||||
.config(toml::toml! {
|
||||
[username]
|
||||
show_always = true
|
||||
|
||||
style_root = ""
|
||||
style_user = ""
|
||||
})
|
||||
.collect();
|
||||
let expected = Some(format!("{} in ", Color::Yellow.bold().paint("astronaut")));
|
||||
let expected = Some("astronaut in ");
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(expected, actual.as_deref());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user