Skip to content

Commit 98d7b86

Browse files
committed
pinky: improve tests
1 parent 1d66824 commit 98d7b86

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

.github/workflows/CICD.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -600,17 +600,6 @@ jobs:
600600
*-pc-windows-msvc) STRIP="" ;;
601601
esac;
602602
outputs STRIP
603-
- name: Install/setup prerequisites
604-
shell: bash
605-
run: |
606-
## Install/setup prerequisites
607-
case '${{ matrix.job.target }}' in
608-
arm-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
609-
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
610-
esac
611-
case '${{ matrix.job.os }}' in
612-
macos-latest) brew install coreutils ;; # needed for testing
613-
esac
614603
- name: Create all needed build/work directories
615604
shell: bash
616605
run: |
@@ -629,6 +618,21 @@ jobs:
629618
case '${{ matrix.job.os }}' in
630619
macos-latest) brew install coreutils ;; # needed for testing
631620
esac
621+
case '${{ matrix.job.os }}' in
622+
ubuntu-*)
623+
# pinky is a tool to show logged-in users from utmp, and gecos fields from /etc/passwd.
624+
# In GitHub Action *nix VMs, no accounts log in, even the "runner" account that runs the commands. The account also has empty gecos fields.
625+
# To work around this for pinky tests, we create a fake login entry for the GH runner account...
626+
FAKE_UTMP='[7] [999999] [tty2] [runner] [tty2] [] [0.0.0.0] [2022-02-22T22:22:22,222222+00:00]'
627+
# ... by dumping the login records, adding our fake line, then reverse dumping ...
628+
(utmpdump /var/run/utmp ; echo $FAKE_UTMP) | sudo utmpdump -r -o /var/run/utmp
629+
# ... and add a full name to each account with a gecos field but no full name.
630+
sudo sed -i 's/:,/:runner name,/' /etc/passwd
631+
# We also create a couple optional files pinky looks for
632+
touch /home/runner/.project
633+
echo "foo" > /home/runner/.plan
634+
;;
635+
esac
632636
- name: rust toolchain ~ install
633637
uses: actions-rs/toolchain@v1
634638
# env:
@@ -899,6 +903,21 @@ jobs:
899903
case '${{ matrix.job.os }}' in
900904
macos-latest) brew install coreutils ;; # needed for testing
901905
esac
906+
case '${{ matrix.job.os }}' in
907+
ubuntu-latest)
908+
# pinky is a tool to show logged-in users from utmp, and gecos fields from /etc/passwd.
909+
# In GitHub Action *nix VMs, no accounts log in, even the "runner" account that runs the commands. The account also has empty gecos fields.
910+
# To work around this for pinky tests, we create a fake login entry for the GH runner account...
911+
FAKE_UTMP='[7] [999999] [tty2] [runner] [tty2] [] [0.0.0.0] [2022-02-22T22:22:22,222222+00:00]'
912+
# ... by dumping the login records, adding our fake line, then reverse dumping ...
913+
(utmpdump /var/run/utmp ; echo $FAKE_UTMP) | sudo utmpdump -r -o /var/run/utmp
914+
# ... and add a full name to each account with a gecos field but no full name.
915+
sudo sed -i 's/:,/:runner name,/' /etc/passwd
916+
# We also create a couple optional files pinky looks for
917+
touch /home/runner/.project
918+
echo "foo" > /home/runner/.plan
919+
;;
920+
esac
902921
- name: rust toolchain ~ install
903922
uses: actions-rs/toolchain@v1
904923
with:

tests/by-util/test_pinky.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ fn test_long_format() {
4444
#[cfg(unix)]
4545
#[test]
4646
fn test_long_format_multiple_users() {
47-
let args = ["-l", "root", "root", "root"];
47+
// multiple instances of one account we know exists,
48+
// the account of the GH runner,
49+
// and an account that (probably) doesn't exist
50+
let args = ["-l", "root", "root", "root", "runner", "no_such_user"];
4851
let ts = TestScenario::new(util_name!());
4952
let expect = unwrap_or_return!(expected_result(&ts, &args));
5053

0 commit comments

Comments
 (0)