Skip to content

Commit f07992e

Browse files
committed
tests/refactor ~ use is_ci() for CI host platform testing
1 parent 9c1818d commit f07992e

4 files changed

Lines changed: 9 additions & 24 deletions

File tree

tests/by-util/test_groups.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ fn test_groups() {
77
let result = ucmd.run();
88
println!("result.stdout {}", result.stdout);
99
println!("result.stderr = {}", result.stderr);
10-
if env::var("USER").is_ok()
11-
&& env::var("USER").unwrap() == "runner"
12-
&& result.stdout.trim().is_empty()
13-
{
10+
if is_ci() && result.stdout.trim().is_empty() {
1411
// In the CI, some server are failing to return the group.
1512
// As seems to be a configuration issue, ignoring it
1613
return;
@@ -26,7 +23,7 @@ fn test_groups_arg() {
2623
println!("result.stdout {}", result.stdout);
2724
println!("result.stderr = {}", result.stderr);
2825
let s1 = String::from(result.stdout.trim());
29-
if s1.parse::<f64>().is_ok() {
26+
if is_ci() && s1.parse::<f64>().is_ok() {
3027
// In the CI, some server are failing to return id -un.
3128
// So, if we are getting a uid, just skip this test
3229
// As seems to be a configuration issue, ignoring it

tests/by-util/test_id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn test_id() {
1414

1515
let uid = String::from(result.stdout.trim());
1616
result = scene.ucmd().run();
17-
if result.stderr.contains("cannot find name for user ID") {
17+
if is_ci() && result.stderr.contains("cannot find name for user ID") {
1818
// In the CI, some server are failing to return whoami.
1919
// As seems to be a configuration issue, ignoring it
2020
return;
@@ -31,7 +31,7 @@ fn test_id() {
3131
fn test_id_from_name() {
3232
let mut scene = TestScenario::new("whoami");
3333
let result = scene.cmd("whoami").run();
34-
if result.stderr.contains("cannot find name for user ID") {
34+
if is_ci() && result.stderr.contains("cannot find name for user ID") {
3535
// In the CI, some server are failing to return whoami.
3636
// As seems to be a configuration issue, ignoring it
3737
return;
@@ -65,7 +65,7 @@ fn test_id_name_from_id() {
6565

6666
scene = TestScenario::new(util_name!());
6767
let result = scene.ucmd().arg("-nu").arg(uid).run();
68-
if result.stderr.contains("No such user/group") {
68+
if is_ci() && result.stderr.contains("No such user/group") {
6969
// In the CI, some server are failing to return whoami.
7070
// As seems to be a configuration issue, ignoring it
7171
return;

tests/by-util/test_logname.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ fn test_normal() {
1313
for (key, value) in env::vars() {
1414
println!("{}: {}", key, value);
1515
}
16-
if env::var("USER").is_ok()
17-
&& env::var("USER").unwrap() == "runner"
18-
&& result.stderr.contains("error: no login name")
19-
{
16+
if is_ci() && result.stderr.contains("error: no login name") {
2017
// In the CI, some server are failing to return logname.
2118
// As seems to be a configuration issue, ignoring it
2219
return;

tests/by-util/test_whoami.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ fn test_normal() {
1313
for (key, value) in env::vars() {
1414
println!("{}: {}", key, value);
1515
}
16-
if env::var("USER").is_ok()
17-
&& env::var("USER").unwrap() == "runner"
18-
&& result.stderr.contains("failed to get username")
19-
{
16+
if is_ci() && result.stderr.contains("failed to get username") {
2017
// In the CI, some server are failing to return whoami.
2118
// As seems to be a configuration issue, ignoring it
2219
return;
@@ -35,10 +32,7 @@ fn test_normal_compare_id() {
3532

3633
println!("result.stdout = {}", result.stdout);
3734
println!("result.stderr = {}", result.stderr);
38-
if env::var("USER").is_ok()
39-
&& env::var("USER").unwrap() == "runner"
40-
&& result.stderr.contains("failed to get username")
41-
{
35+
if is_ci() && result.stderr.contains("failed to get username") {
4236
// In the CI, some server are failing to return whoami.
4337
// As seems to be a configuration issue, ignoring it
4438
return;
@@ -47,10 +41,7 @@ fn test_normal_compare_id() {
4741
let ts = TestScenario::new("id");
4842
let id = ts.cmd("id").arg("-un").run();
4943

50-
if env::var("USER").is_ok()
51-
&& env::var("USER").unwrap() == "runner"
52-
&& id.stderr.contains("cannot find name for user ID")
53-
{
44+
if is_ci() && id.stderr.contains("cannot find name for user ID") {
5445
// In the CI, some server are failing to return whoami.
5546
// As seems to be a configuration issue, ignoring it
5647
return;

0 commit comments

Comments
 (0)