Skip to content

Commit 42b7c68

Browse files
committed
pinky: improve tests
1 parent f2f48e6 commit 42b7c68

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

.github/workflows/CICD.yml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,6 @@ jobs:
595595
*-pc-windows-msvc) STRIP="" ;;
596596
esac;
597597
outputs STRIP
598-
- name: Install/setup prerequisites
599-
shell: bash
600-
run: |
601-
## Install/setup prerequisites
602-
case '${{ matrix.job.target }}' in
603-
arm-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
604-
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
605-
esac
606-
case '${{ matrix.job.os }}' in
607-
macos-latest) brew install coreutils ;; # needed for testing
608-
esac
609598
- name: Create all needed build/work directories
610599
shell: bash
611600
run: |
@@ -624,6 +613,19 @@ jobs:
624613
case '${{ matrix.job.os }}' in
625614
macos-latest) brew install coreutils ;; # needed for testing
626615
esac
616+
case '${{ matrix.job.os }}' in
617+
*linux*)
618+
# pinky is a tool that shows logged-in users from utmp, and gecos fields from /etc/passwd,
619+
# but the runner account doesn't log in (nor does any other), and has empty gecos fields.
620+
# To work around this for tests, we...
621+
# ... create a fake login entry for the GH runner...
622+
FAKE_UTMP='[7] [999999] [tty2] [runner] [tty2] [] [0.0.0.0] [2022-02-20T22:22:22,222222+00:00]'
623+
# ... by dumping the login records, adding our fake line, then reverse dumping ...
624+
(utmpdump /var/run/utmp ; echo $FAKE_UTMP) | sudo utmpdump -r -o /var/run/utmp
625+
# ... and add a full name to each account with at a gecos field but no full name.
626+
sudo sed -i 's/:,/:runner name,/' /etc/passwd
627+
;;
628+
esac
627629
- name: rust toolchain ~ install
628630
uses: actions-rs/toolchain@v1
629631
# env:
@@ -894,6 +896,19 @@ jobs:
894896
case '${{ matrix.job.os }}' in
895897
macos-latest) brew install coreutils ;; # needed for testing
896898
esac
899+
case '${{ matrix.job.os }}' in
900+
*linux*)
901+
# pinky is a tool that shows logged-in users from utmp, and gecos fields from /etc/passwd,
902+
# but the runner account doesn't log in (nor does any other), and has empty gecos fields.
903+
# To work around this for tests, we...
904+
# ... create a fake login entry for the GH runner...
905+
FAKE_UTMP='[7] [999999] [tty2] [runner] [tty2] [] [0.0.0.0] [2022-02-20T22:22:22,222222+00:00]'
906+
# ... by dumping the login records, adding our fake line, then reverse dumping ...
907+
(utmpdump /var/run/utmp ; echo $FAKE_UTMP) | sudo utmpdump -r -o /var/run/utmp
908+
# ... and add a full name to each account with at a gecos field but no full name.
909+
sudo sed -i 's/:,/:runner name,/' /etc/passwd
910+
;;
911+
esac
897912
- name: rust toolchain ~ install
898913
uses: actions-rs/toolchain@v1
899914
with:

tests/by-util/test_pinky.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn test_long_format() {
4444
#[cfg(unix)]
4545
#[test]
4646
fn test_long_format_multiple_users() {
47-
let args = ["-l", "root", "root", "root"];
47+
let args = ["-l", "root", "root", "root", "runner"];
4848
let ts = TestScenario::new(util_name!());
4949
let expect = unwrap_or_return!(expected_result(&ts, &args));
5050

0 commit comments

Comments
 (0)