From 0ca5132a06add8d67583836ffb5e0e5608b6cd36 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 15 May 2020 14:19:40 +0200 Subject: [PATCH] test(whoami): Add test for whoami (#1506) * test(whoami): Add test for whoami Side effect: also tests "id -un" --- tests/test_whoami.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++ tests/tests.rs | 1 + 2 files changed, 59 insertions(+) create mode 100644 tests/test_whoami.rs diff --git a/tests/test_whoami.rs b/tests/test_whoami.rs new file mode 100644 index 000000000..1a95f5274 --- /dev/null +++ b/tests/test_whoami.rs @@ -0,0 +1,58 @@ +use common::util::*; +use std::env; + +#[test] +fn test_normal() { + let (_, mut ucmd) = at_and_ucmd!(); + + let result = ucmd.run(); + println!("result.stdout = {}", result.stdout); + println!("result.stderr = {}", result.stderr); + println!("env::var(CI).is_ok() = {}", env::var("CI").is_ok()); + + for (key, value) in env::vars() { + println!("{}: {}", key, value); + } + if env::var("USER").is_ok() + && env::var("USER").unwrap() == "runner" + && result.stderr.contains("failed to get username") + { + // In the CI, some server are failing to return whoami. + // As seems to be a configuration issue, ignoring it + return; + } + + assert!(result.success); + assert!(!result.stdout.trim().is_empty()); +} + +#[test] +fn test_normal_compare_id() { + let (_, mut ucmd) = at_and_ucmd!(); + + let result = ucmd.run(); + + println!("result.stdout = {}", result.stdout); + println!("result.stderr = {}", result.stderr); + if env::var("USER").is_ok() + && env::var("USER").unwrap() == "runner" + && result.stderr.contains("failed to get username") + { + // In the CI, some server are failing to return whoami. + // As seems to be a configuration issue, ignoring it + return; + } + assert!(result.success); + let ts = TestScenario::new("id"); + let id = ts.cmd("id").arg("-un").run(); + + if env::var("USER").is_ok() + && env::var("USER").unwrap() == "runner" + && id.stderr.contains("cannot find name for user ID") + { + // In the CI, some server are failing to return whoami. + // As seems to be a configuration issue, ignoring it + return; + } + assert_eq!(result.stdout.trim(), id.stdout.trim()); +} diff --git a/tests/tests.rs b/tests/tests.rs index 189cdb988..ed1271744 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -104,6 +104,7 @@ generic! { "unexpand", test_unexpand; "uniq", test_uniq; "wc", test_wc; + "whoami", test_whoami; // Be aware of the trailing semicolon after the last item "hostname", test_hostname }