test: allow running tests as root (#2571)
This commit is contained in:
parent
6817e7f698
commit
436eb61efd
|
@ -514,6 +514,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn directory_in_root() {
|
fn directory_in_root() {
|
||||||
let actual = ModuleRenderer::new("directory").path("/etc").collect();
|
let actual = ModuleRenderer::new("directory").path("/etc").collect();
|
||||||
let expected = Some(format!(
|
let expected = Some(format!(
|
||||||
|
|
|
@ -86,7 +86,6 @@ fn is_ssh_session(context: &Context) -> bool {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::test::ModuleRenderer;
|
use crate::test::ModuleRenderer;
|
||||||
use ansi_term::Color;
|
|
||||||
|
|
||||||
// TODO: Add tests for if root user (UID == 0)
|
// TODO: Add tests for if root user (UID == 0)
|
||||||
// Requires mocking
|
// Requires mocking
|
||||||
|
@ -100,6 +99,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn no_logname_env_variable() {
|
fn no_logname_env_variable() {
|
||||||
let actual = ModuleRenderer::new("username")
|
let actual = ModuleRenderer::new("username")
|
||||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||||
|
@ -110,6 +110,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn logname_equals_user() {
|
fn logname_equals_user() {
|
||||||
let actual = ModuleRenderer::new("username")
|
let actual = ModuleRenderer::new("username")
|
||||||
.env("LOGNAME", "astronaut")
|
.env("LOGNAME", "astronaut")
|
||||||
|
@ -136,10 +137,16 @@ mod tests {
|
||||||
let actual = ModuleRenderer::new("username")
|
let actual = ModuleRenderer::new("username")
|
||||||
.env("LOGNAME", "astronaut")
|
.env("LOGNAME", "astronaut")
|
||||||
.env(super::USERNAME_ENV_VAR, "cosmonaut")
|
.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();
|
.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]
|
#[test]
|
||||||
|
@ -147,10 +154,16 @@ mod tests {
|
||||||
let actual = ModuleRenderer::new("username")
|
let actual = ModuleRenderer::new("username")
|
||||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||||
.env("SSH_CONNECTION", "192.168.223.17 36673 192.168.223.229 22")
|
.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();
|
.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]
|
#[test]
|
||||||
|
@ -158,10 +171,16 @@ mod tests {
|
||||||
let actual = ModuleRenderer::new("username")
|
let actual = ModuleRenderer::new("username")
|
||||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||||
.env("SSH_TTY", "/dev/pts/0")
|
.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();
|
.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]
|
#[test]
|
||||||
|
@ -169,23 +188,33 @@ mod tests {
|
||||||
let actual = ModuleRenderer::new("username")
|
let actual = ModuleRenderer::new("username")
|
||||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||||
.env("SSH_CLIENT", "192.168.0.101 39323 22")
|
.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();
|
.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]
|
#[test]
|
||||||
fn show_always() {
|
fn show_always() {
|
||||||
let actual = ModuleRenderer::new("username")
|
let actual = ModuleRenderer::new("username")
|
||||||
.env(super::USERNAME_ENV_VAR, "astronaut")
|
.env(super::USERNAME_ENV_VAR, "astronaut")
|
||||||
|
// Test output should not change when run by root/non-root user
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
[username]
|
[username]
|
||||||
show_always = true
|
show_always = true
|
||||||
|
|
||||||
|
style_root = ""
|
||||||
|
style_user = ""
|
||||||
})
|
})
|
||||||
.collect();
|
.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