Skip to content

Commit

Permalink
test/system: Simplify code
Browse files Browse the repository at this point in the history
There's no need to run these cat(1) and gdbus(1) invocations through a
shell (ie., 'sh -c'), because there's no shell expansion that needs to
be performed.

These are unlike cases where shell expansion does need to be performed.
eg., 'readlink /proc/$$/ns/user', where the $$ needs to be expanded.

Fallout from 58134f8 and
a0514cb
  • Loading branch information
debarshiray committed Nov 30, 2023
1 parent f28ad77 commit e71c057
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions test/system/206-user.bats
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ teardown() {

create_default_container

run --keep-empty-lines --separate-stderr "$TOOLBOX" run sh -c 'cat /etc/passwd'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run cat /etc/passwd

assert_success
assert_line --regexp "^$USER::$user_id_real:$user_id_real:$user_gecos:$HOME:$SHELL$"
Expand All @@ -201,7 +201,7 @@ teardown() {

create_distro_container arch latest arch-toolbox-latest

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro arch sh -c 'cat /etc/passwd'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro arch cat /etc/passwd

assert_success
assert_line --regexp "^$USER::$user_id_real:$user_id_real:$user_gecos:$HOME:$SHELL$"
Expand All @@ -220,7 +220,7 @@ teardown() {

create_distro_container fedora 34 fedora-toolbox-34

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro fedora --release 34 sh -c 'cat /etc/passwd'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro fedora --release 34 cat /etc/passwd

assert_success
assert_line --regexp "^$USER::$user_id_real:$user_id_real:$user_gecos:$HOME:$SHELL$"
Expand All @@ -239,7 +239,7 @@ teardown() {

create_distro_container rhel 8.7 rhel-toolbox-8.7

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro rhel --release 8.7 sh -c 'cat /etc/passwd'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro rhel --release 8.7 cat /etc/passwd

assert_success
assert_line --regexp "^$USER::$user_id_real:$user_id_real:$user_gecos:$HOME:$SHELL$"
Expand All @@ -258,7 +258,7 @@ teardown() {

create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 16.04 sh -c 'cat /etc/passwd'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 16.04 cat /etc/passwd

assert_success
assert_line --regexp "^$USER::$user_id_real:$user_id_real:$user_gecos:$HOME:$SHELL$"
Expand All @@ -277,7 +277,7 @@ teardown() {

create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 18.04 sh -c 'cat /etc/passwd'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 18.04 cat /etc/passwd

assert_success
assert_line --regexp "^$USER::$user_id_real:$user_id_real:$user_gecos:$HOME:$SHELL$"
Expand All @@ -296,7 +296,7 @@ teardown() {

create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 20.04 sh -c 'cat /etc/passwd'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 20.04 cat /etc/passwd

assert_success
assert_line --regexp "^$USER::$user_id_real:$user_id_real:$user_gecos:$HOME:$SHELL$"
Expand Down Expand Up @@ -431,7 +431,7 @@ teardown() {
@test "user: $USER in group(5) inside the default container" {
create_default_container

run --keep-empty-lines --separate-stderr "$TOOLBOX" run sh -c 'cat /etc/group'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run cat /etc/group

assert_success
assert_line --regexp "^(sudo|wheel):x:[[:digit:]]+:$USER$"
Expand All @@ -444,7 +444,7 @@ teardown() {
@test "user: $USER in group(5) inside Arch Linux" {
create_distro_container arch latest arch-toolbox-latest

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro arch sh -c 'cat /etc/group'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro arch cat /etc/group

assert_success
assert_line --regexp "^wheel:x:[[:digit:]]+:$USER$"
Expand All @@ -457,7 +457,7 @@ teardown() {
@test "user: $USER in group(5) inside Fedora 34" {
create_distro_container fedora 34 fedora-toolbox-34

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro fedora --release 34 sh -c 'cat /etc/group'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro fedora --release 34 cat /etc/group

assert_success
assert_line --regexp "^wheel:x:[[:digit:]]+:$USER$"
Expand All @@ -470,7 +470,7 @@ teardown() {
@test "user: $USER in group(5) inside RHEL 8.7" {
create_distro_container rhel 8.7 rhel-toolbox-8.7

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro rhel --release 8.7 sh -c 'cat /etc/group'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro rhel --release 8.7 cat /etc/group

assert_success
assert_line --regexp "^wheel:x:[[:digit:]]+:$USER$"
Expand All @@ -483,7 +483,7 @@ teardown() {
@test "user: $USER in group(5) inside Ubuntu 16.04" {
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 16.04 sh -c 'cat /etc/group'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 16.04 cat /etc/group

assert_success
assert_line --regexp "^sudo:x:[[:digit:]]+:$USER$"
Expand All @@ -496,7 +496,7 @@ teardown() {
@test "user: $USER in group(5) inside Ubuntu 18.04" {
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 18.04 sh -c 'cat /etc/group'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 18.04 cat /etc/group

assert_success
assert_line --regexp "^sudo:x:[[:digit:]]+:$USER$"
Expand All @@ -509,7 +509,7 @@ teardown() {
@test "user: $USER in group(5) inside Ubuntu 20.04" {
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04

run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 20.04 sh -c 'cat /etc/group'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run --distro ubuntu --release 20.04 cat /etc/group

assert_success
assert_line --regexp "^sudo:x:[[:digit:]]+:$USER$"
Expand Down
22 changes: 11 additions & 11 deletions test/system/211-dbus.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ teardown() {

create_default_container

run --keep-empty-lines --separate-stderr "$TOOLBOX" run sh -c 'gdbus call \
--session \
--dest org.freedesktop.DBus \
--object-path /org/freedesktop/DBus \
--method org.freedesktop.DBus.Peer.Ping'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run gdbus call \
--session \
--dest org.freedesktop.DBus \
--object-path /org/freedesktop/DBus \
--method org.freedesktop.DBus.Peer.Ping

assert_success
assert_line --index 0 "$expected_response"
Expand All @@ -68,12 +68,12 @@ teardown() {

create_default_container

run --keep-empty-lines --separate-stderr "$TOOLBOX" run sh -c 'gdbus call \
--system \
--dest org.freedesktop.systemd1 \
--object-path /org/freedesktop/systemd1 \
--method org.freedesktop.DBus.Properties.Get \
org.freedesktop.systemd1.Manager Version'
run --keep-empty-lines --separate-stderr "$TOOLBOX" run gdbus call \
--system \
--dest org.freedesktop.systemd1 \
--object-path /org/freedesktop/systemd1 \
--method org.freedesktop.DBus.Properties.Get \
org.freedesktop.systemd1.Manager Version

assert_success
assert_line --index 0 "$expected_response"
Expand Down

0 comments on commit e71c057

Please sign in to comment.