1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

test: allow running tests as root (#2571)

This commit is contained in:
David Knaack 2021-04-10 19:05:46 +02:00 committed by GitHub
parent 6817e7f698
commit 436eb61efd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 11 deletions

View File

@ -514,6 +514,7 @@ mod tests {
}
#[test]
#[ignore]
fn directory_in_root() {
let actual = ModuleRenderer::new("directory").path("/etc").collect();
let expected = Some(format!(

View File

@ -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());
}
}