tests: cleanup the basic structure of integration tests.

This commit is contained in:
Alexandre Pujol 2024-11-19 21:27:04 +00:00
parent 206bc3473d
commit 5c70c50c26
Failed to generate hash of commit
45 changed files with 49 additions and 501 deletions

View file

@ -10,26 +10,18 @@ setup_file() {
skip skip
} }
# bats test_tags=aa-enforce
@test "aa-enforce: Disable profile" { @test "aa-enforce: Disable profile" {
sudo aa-disable pass sudo aa-disable pass
aa_check
} }
# bats test_tags=aa-enforce
@test "aa-enforce: Enforce a profile" { @test "aa-enforce: Enforce a profile" {
sudo aa-enforce pass sudo aa-enforce pass
aa_check
} }
# bats test_tags=aa-enforce
@test "aa-enforce: Complain a profile" { @test "aa-enforce: Complain a profile" {
sudo aa-complain pass sudo aa-complain pass
aa_check
} }
# bats test_tags=aa-enforce
@test "aa-enforce: Audit a profile" { @test "aa-enforce: Audit a profile" {
sudo aa-audit pass sudo aa-audit pass
aa_check
} }

View file

@ -5,36 +5,22 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=aa-status
@test "aa-status: Check status" { @test "aa-status: Check status" {
sudo aa-status sudo aa-status
aa_check
} }
# bats test_tags=aa-status
@test "aa-status: Display the number of loaded policies" { @test "aa-status: Display the number of loaded policies" {
sudo aa-status --profiled sudo aa-status --profiled
aa_check
} }
# bats test_tags=aa-status
@test "aa-status: Display the number of loaded enforicing policies" { @test "aa-status: Display the number of loaded enforicing policies" {
sudo aa-status --enforced sudo aa-status --enforced
aa_check
} }
# bats test_tags=aa-status
@test "aa-status: Display the number of loaded non-enforcing policies" { @test "aa-status: Display the number of loaded non-enforcing policies" {
sudo aa-status --complaining sudo aa-status --complaining
aa_check
} }
# bats test_tags=aa-status
@test "aa-status: Display the number of loaded enforcing policies that kill tasks" { @test "aa-status: Display the number of loaded enforcing policies that kill tasks" {
sudo aa-status --kill sudo aa-status --kill
aa_check
} }

View file

@ -5,18 +5,10 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=blkid
@test "blkid: List all partitions" { @test "blkid: List all partitions" {
sudo blkid sudo blkid
aa_check
} }
# bats test_tags=blkid
@test "blkid: List all partitions in a table, including current mountpoints" { @test "blkid: List all partitions in a table, including current mountpoints" {
sudo blkid -o list sudo blkid -o list
aa_check
} }

View file

@ -5,24 +5,15 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=chsh
@test "chsh: [l]ist available shells" { @test "chsh: [l]ist available shells" {
chsh --list-shells || true chsh --list-shells || true
aa_check
} }
# bats test_tags=chsh
@test "chsh: Set a specific login [s]hell for the current user" { @test "chsh: Set a specific login [s]hell for the current user" {
echo "$PASSWORD" | chsh --shell /usr/bin/bash echo "$PASSWORD" | chsh --shell /usr/bin/bash
aa_check
} }
# bats test_tags=chsh # bats test_tags=chsh
@test "chsh: Set a login [s]hell for a specific user" { @test "chsh: Set a login [s]hell for a specific user" {
sudo chsh --shell /usr/bin/sh root sudo chsh --shell /usr/bin/sh root
aa_check
} }

View file

@ -105,8 +105,18 @@ aa_check() {
now=$(date +%s) now=$(date +%s)
duration=$((now - _START + 1)) duration=$((now - _START + 1))
logs=$(aa-log --raw --systemd --since "-${duration}s") logs=$(aa-log --raw --systemd --since "-${duration}s")
aa_start
if [[ -n "$logs" ]]; then if [[ -n "$logs" ]]; then
fail "profile $PROGRAM raised logs: $logs" fail "profile $PROGRAM raised logs: $logs"
fi fi
aa_start }
# Bats setup and teardown hooks
setup_file() {
aa_setup
}
teardown() {
aa_check
} }

View file

@ -5,24 +5,14 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=cpuid
@test "cpuid: Display information for all CPUs" { @test "cpuid: Display information for all CPUs" {
cpuid cpuid
aa_check
} }
# bats test_tags=cpuid
@test "cpuid: Display information only for the current CPU" { @test "cpuid: Display information only for the current CPU" {
cpuid -1 cpuid -1
aa_check
} }
# bats test_tags=cpuid
@test "cpuid: Display raw hex information with no decoding" { @test "cpuid: Display raw hex information with no decoding" {
cpuid -r cpuid -r
aa_check
} }

View file

@ -5,36 +5,22 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=df
@test "df: Display all filesystems and their disk usage" { @test "df: Display all filesystems and their disk usage" {
df df
aa_check
} }
# bats test_tags=df
@test "df: Display all filesystems and their disk usage in human-readable form" { @test "df: Display all filesystems and their disk usage in human-readable form" {
df -h df -h
aa_check
} }
# bats test_tags=df
@test "df: Display the filesystem and its disk usage containing the given file or directory" { @test "df: Display the filesystem and its disk usage containing the given file or directory" {
df apparmor.d/ df apparmor.d/
aa_check
} }
# bats test_tags=df
@test "df: Include statistics on the number of free inodes" { @test "df: Include statistics on the number of free inodes" {
df --inodes df --inodes
aa_check
} }
# bats test_tags=df
@test "df: Display filesystem types" { @test "df: Display filesystem types" {
df --print-type df --print-type
aa_check
} }

View file

@ -5,30 +5,18 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=dfc
@test "dfc: Display filesystems and their disk usage in human-readable form with colors and graphs" { @test "dfc: Display filesystems and their disk usage in human-readable form with colors and graphs" {
dfc dfc
aa_check
} }
# bats test_tags=dfc
@test "dfc: Display all filesystems including pseudo, duplicate and inaccessible filesystems" { @test "dfc: Display all filesystems including pseudo, duplicate and inaccessible filesystems" {
dfc -a dfc -a
aa_check
} }
# bats test_tags=dfc
@test "dfc: Display filesystems without color" { @test "dfc: Display filesystems without color" {
dfc -c never dfc -c never
aa_check
} }
# bats test_tags=dfc
@test "dfc: Display filesystems containing "ext" in the filesystem type" { @test "dfc: Display filesystems containing "ext" in the filesystem type" {
dfc -t ext dfc -t ext
aa_check
} }

View file

@ -5,25 +5,14 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=fc-cache
@test "fc-cache: Generate font cache files" { @test "fc-cache: Generate font cache files" {
fc-cache fc-cache
aa_check
} }
# bats test_tags=fc-cache
@test "fc-cache: Force a rebuild of all font cache files, without checking if cache is up-to-date" { @test "fc-cache: Force a rebuild of all font cache files, without checking if cache is up-to-date" {
fc-cache -f fc-cache -f
aa_check
} }
# bats test_tags=fc-cache
@test "fc-cache: Erase font cache files, then generate new font cache files" { @test "fc-cache: Erase font cache files, then generate new font cache files" {
fc-cache -r fc-cache -r
aa_check
} }

View file

@ -5,12 +5,6 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=fc-list
@test "fc-list: Return a list of installed fonts in your system" { @test "fc-list: Return a list of installed fonts in your system" {
fc-list fc-list
aa_check
} }

View file

@ -5,48 +5,30 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=flatpak
@test "flatpak: List installed applications, ignoring runtimes" { @test "flatpak: List installed applications, ignoring runtimes" {
flatpak list --app flatpak list --app
aa_check
} }
# bats test_tags=flatpak
@test "flatpak: Install an application from a remote source" { @test "flatpak: Install an application from a remote source" {
flatpak install --noninteractive org.vim.Vim flatpak install --noninteractive org.vim.Vim
aa_check
} }
# bats test_tags=flatpak
@test "flatpak: Show information about an installed application" { @test "flatpak: Show information about an installed application" {
flatpak info org.vim.Vim flatpak info org.vim.Vim
aa_check
} }
# bats test_tags=flatpak
@test "flatpak: Run an installed application" { @test "flatpak: Run an installed application" {
flatpak run org.vim.Vim flatpak run org.vim.Vim
aa_check
} }
# bats test_tags=flatpak
@test "flatpak: Update all installed applications and runtimes" { @test "flatpak: Update all installed applications and runtimes" {
flatpak update --noninteractive flatpak update --noninteractive
aa_check
} }
# bats test_tags=flatpak
@test "flatpak: Remove an installed application" { @test "flatpak: Remove an installed application" {
flatpak remove --noninteractive org.vim.Vim flatpak remove --noninteractive org.vim.Vim
aa_check
} }
# bats test_tags=flatpak
@test "flatpak: Remove all unused applications" { @test "flatpak: Remove all unused applications" {
flatpak remove --unused flatpak remove --unused
aa_check
} }

View file

@ -5,44 +5,30 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=gpgconf
@test "gpgconf: List all components" { @test "gpgconf: List all components" {
gpgconf --list-components gpgconf --list-components
aa_check
} }
# bats test_tags=gpgconf
@test "gpgconf: List the directories used by gpgconf" { @test "gpgconf: List the directories used by gpgconf" {
gpgconf --list-dirs gpgconf --list-dirs
aa_check
} }
# bats test_tags=gpgconf
@test "gpgconf: List all options of a component" { @test "gpgconf: List all options of a component" {
gpgconf --list-options gpg gpgconf --list-options gpg
gpgconf --list-options gpgsm gpgconf --list-options gpgsm
gpgconf --list-options gpg-agent gpgconf --list-options gpg-agent
gpgconf --list-options scdaemon || true gpgconf --list-options scdaemon || true
gpgconf --list-options dirmngr gpgconf --list-options dirmngr
aa_check
} }
# bats test_tags=gpgconf
@test "gpgconf: List programs and test whether they are runnable" { @test "gpgconf: List programs and test whether they are runnable" {
gpgconf --check-programs || true gpgconf --check-programs || true
aa_check
} }
# bats test_tags=gpgconf
@test "gpgconf: Reload a component" { @test "gpgconf: Reload a component" {
gpgconf --reload gpg gpgconf --reload gpg
gpgconf --reload gpgsm gpgconf --reload gpgsm
gpgconf --reload gpg-agent gpgconf --reload gpg-agent
gpgconf --reload scdaemon || true gpgconf --reload scdaemon || true
gpgconf --reload dirmngr gpgconf --reload dirmngr
aa_check
} }

View file

@ -5,32 +5,20 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=groupadd
@test "groupadd: Create a new group" { @test "groupadd: Create a new group" {
sudo groupadd user2 sudo groupadd user2
aa_check
} }
# bats test_tags=groupadd
@test "groupadd: Create a new system group" { @test "groupadd: Create a new system group" {
sudo groupadd --system system2 sudo groupadd --system system2
aa_check
} }
# bats test_tags=groupadd
@test "groupadd: Create a new group with the specific groupid" { @test "groupadd: Create a new group with the specific groupid" {
sudo groupadd --gid 3000 user3 sudo groupadd --gid 3000 user3
aa_check
} }
# bats test_tags=groupadd
@test "groupdel: Delete newly created group" { @test "groupdel: Delete newly created group" {
sudo groupdel user2 sudo groupdel user2
sudo groupdel system2 sudo groupdel system2
sudo groupdel user3 sudo groupdel user3
aa_check
} }

View file

@ -5,19 +5,11 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=groups
@test "groups: Print group memberships for the current user" { @test "groups: Print group memberships for the current user" {
groups groups
aa_check
} }
# bats test_tags=groups
@test "groups: Print group memberships for a list of users" { @test "groups: Print group memberships for a list of users" {
groups root groups root
aa_check
} }

View file

@ -10,50 +10,34 @@ setup_file() {
skip skip
} }
# bats test_tags=homectl
@test "homectl: Display help" { @test "homectl: Display help" {
homectl --no-pager --help homectl --no-pager --help
aa_check
} }
# bats test_tags=homectl
@test "homectl: Create a user account and their associated home directory" { @test "homectl: Create a user account and their associated home directory" {
sudo homectl create user2 sudo homectl create user2
aa_check
} }
# bats test_tags=homectl
@test "homectl: List user accounts and their associated home directories" { @test "homectl: List user accounts and their associated home directories" {
homectl list homectl list
aa_check
} }
# bats test_tags=homectl
@test "homectl: Change the password for a specific user" { @test "homectl: Change the password for a specific user" {
sudo homectl passwd user2 sudo homectl passwd user2
aa_check
} }
# bats test_tags=homectl
@test "homectl: Run a shell or a command with access to a specific home directory" { @test "homectl: Run a shell or a command with access to a specific home directory" {
sudo homectl with user2 -- ls -al /home/user2 sudo homectl with user2 -- ls -al /home/user2
aa_check
} }
# bats test_tags=homectl
@test "homectl: Lock or unlock a specific home directory" { @test "homectl: Lock or unlock a specific home directory" {
sudo homectl lock user2 sudo homectl lock user2
aa_check
} }
# bats test_tags=homectl
@test "homectl: Change the disk space assigned to a specific home directory to 100 GiB" { @test "homectl: Change the disk space assigned to a specific home directory to 100 GiB" {
sudo homectl resize user2 1G sudo homectl resize user2 1G
aa_check
} }
# bats test_tags=homectl
@test "homectl: Remove a specific user and the associated home directory" { @test "homectl: Remove a specific user and the associated home directory" {
sudo homectl remove user2 sudo homectl remove user2
aa_check
} }

View file

@ -5,21 +5,14 @@
load common load common
setup() {
aa_setup
}
# bats test_tags=hostnamectl
@test "hostnamectl: Get the hostname of the computer" { @test "hostnamectl: Get the hostname of the computer" {
hostnamectl hostnamectl
} }
# bats test_tags=hostnamectl
@test "hostnamectl: Get the location of the computer" { @test "hostnamectl: Get the location of the computer" {
hostnamectl location hostnamectl location
} }
# bats test_tags=hostnamectl
@test "hostnamectl: Set the hostname of the computer" { @test "hostnamectl: Set the hostname of the computer" {
name=$(hostnamectl hostname) name=$(hostnamectl hostname)
sudo hostnamectl set-hostname "new" sudo hostnamectl set-hostname "new"

View file

@ -5,41 +5,26 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=id
@test "id: Display current user's ID (UID), group ID (GID) and groups to which they belong" { @test "id: Display current user's ID (UID), group ID (GID) and groups to which they belong" {
id id
aa_check
} }
# bats test_tags=id
@test "id: Display the current user identity" { @test "id: Display the current user identity" {
id -un id -un
aa_check
} }
# bats test_tags=id
@test "id: Display the current user identity as a number" { @test "id: Display the current user identity as a number" {
id -u id -u
aa_check
} }
# bats test_tags=id
@test "id: Display the current primary group identity" { @test "id: Display the current primary group identity" {
id -gn id -gn
aa_check
} }
# bats test_tags=id
@test "id: Display the current primary group identity as a number" { @test "id: Display the current primary group identity as a number" {
id -g id -g
aa_check
} }
# bats test_tags=id
@test "id: Display an arbitrary user ID (UID), group ID (GID) and groups to which they belong" { @test "id: Display an arbitrary user ID (UID), group ID (GID) and groups to which they belong" {
id root id root
} }

View file

@ -5,41 +5,42 @@
load common load common
setup_file() { @test "ip-address: List network interfaces and their associated IP addresses" {
aa_setup
}
# bats test_tags=ip
@test "ip: List interfaces with detailed info" {
ip address ip address
aa_check
} }
# bats test_tags=ip @test "ip-address: Filter to show only active network interfaces" {
@test "ip: List interfaces with brief link layer info" { ip address show up
ip link
aa_check
} }
# bats test_tags=ip @test "ip-route: Display the routing table" {
@test "ip: Display the routing table" {
ip route ip route
aa_check
} }
# bats test_tags=ip @test "ip-route-get: Print route to a destination" {
@test "ip: Show neighbors (ARP table)" { ip route get 1.1.1.1
}
@test "ip link: Show information about all network interfaces" {
ip link
}
@test "ip neighbour: Display the neighbour/ARP table entries" {
ip neighbour ip neighbour
aa_check
} }
# bats test_tags=ip @test "ip rule: Display the routing policy" {
ip rule show
ip rule list
}
@test "ip rule: Flush all deleted rules" {
ip rule flush
}
@test "ip: Manage network namespace" { @test "ip: Manage network namespace" {
sudo ip netns add foo sudo ip netns add foo
sudo ip netns list sudo ip netns list
sudo ip netns exec foo bash -c "pwd" sudo ip netns exec foo bash -c "pwd"
sudo ip netns delete foo sudo ip netns delete foo
aa_check
} }

View file

@ -5,54 +5,34 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=lsblk
@test "lsblk: List all storage devices in a tree-like format" { @test "lsblk: List all storage devices in a tree-like format" {
lsblk lsblk
aa_check
} }
# bats test_tags=lsblk
@test "lsblk: Also list empty devices" { @test "lsblk: Also list empty devices" {
lsblk -a lsblk -a
aa_check
} }
# bats test_tags=lsblk
@test "lsblk: Print the SIZE column in bytes rather than in a human-readable format" { @test "lsblk: Print the SIZE column in bytes rather than in a human-readable format" {
lsblk -b lsblk -b
aa_check
} }
# bats test_tags=lsblk
@test "lsblk: Output info about filesystems" { @test "lsblk: Output info about filesystems" {
lsblk -f lsblk -f
aa_check
} }
# bats test_tags=lsblk
@test "lsblk: Use ASCII characters for tree formatting" { @test "lsblk: Use ASCII characters for tree formatting" {
lsblk -i lsblk -i
aa_check
} }
# bats test_tags=lsblk
@test "lsblk: Output info about block-device topology" { @test "lsblk: Output info about block-device topology" {
lsblk -t lsblk -t
aa_check
} }
# bats test_tags=lsblk
@test "lsblk: Exclude the devices specified by the comma-separated list of major device numbers" { @test "lsblk: Exclude the devices specified by the comma-separated list of major device numbers" {
lsblk -e 1 lsblk -e 1
aa_check
} }
# bats test_tags=lsblk
@test "lsblk: Display a customized summary using a comma-separated list of columns" { @test "lsblk: Display a customized summary using a comma-separated list of columns" {
lsblk --output NAME,SERIAL,MODEL,TRAN,TYPE,SIZE,FSTYPE,MOUNTPOINT lsblk --output NAME,SERIAL,MODEL,TRAN,TYPE,SIZE,FSTYPE,MOUNTPOINT
aa_check
} }

View file

@ -5,24 +5,14 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=lscpu
@test "lscpu: Display information about all CPUs" { @test "lscpu: Display information about all CPUs" {
lscpu lscpu
aa_check
} }
# bats test_tags=lscpu
@test "lscpu: Display information in a table" { @test "lscpu: Display information in a table" {
lscpu --extended lscpu --extended
aa_check
} }
# bats test_tags=lscpu
@test "lscpu: Display only information about offline CPUs in a table" { @test "lscpu: Display only information about offline CPUs in a table" {
lscpu --extended --offline lscpu --extended --offline
aa_check
} }

View file

@ -5,36 +5,22 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=lspci
@test "lspci: Show a brief list of devices" { @test "lspci: Show a brief list of devices" {
lspci lspci
aa_check
} }
# bats test_tags=lspci
@test "lspci: Display additional info" { @test "lspci: Display additional info" {
lspci -v lspci -v
aa_check
} }
# bats test_tags=lspci
@test "lspci: Display drivers and modules handling each device" { @test "lspci: Display drivers and modules handling each device" {
lspci -k lspci -k
aa_check
} }
# bats test_tags=lspci
@test "lspci: Show a specific device" { @test "lspci: Show a specific device" {
lspci -s 00:00.0 lspci -s 00:00.0
aa_check
} }
# bats test_tags=lspci
@test "lspci: Dump info in a readable form" { @test "lspci: Dump info in a readable form" {
lspci -vm lspci -vm
aa_check
} }

View file

@ -5,24 +5,14 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=lsusb
@test "lsusb: List all the USB devices available" { @test "lsusb: List all the USB devices available" {
lsusb || true lsusb || true
aa_check
} }
# bats test_tags=lsusb
@test "lsusb: List the USB hierarchy as a tree" { @test "lsusb: List the USB hierarchy as a tree" {
lsusb -t || true lsusb -t || true
aa_check
} }
# bats test_tags=lsusb
@test "lsusb: List verbose information about USB devices" { @test "lsusb: List verbose information about USB devices" {
lsusb --verbose || true lsusb --verbose || true
aa_check
} }

View file

@ -5,42 +5,26 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=ps
@test "ps: List all running processes" { @test "ps: List all running processes" {
ps aux ps aux
aa_check
} }
# bats test_tags=ps
@test "ps: List all running processes including the full command string" { @test "ps: List all running processes including the full command string" {
ps auxww ps auxww
aa_check
} }
# bats test_tags=ps
@test "ps: List all processes of the current user in extra full format" { @test "ps: List all processes of the current user in extra full format" {
ps --user "$(id -u)" -F ps --user "$(id -u)" -F
aa_check
} }
# bats test_tags=ps
@test "ps: List all processes of the current user as a tree" { @test "ps: List all processes of the current user as a tree" {
ps --user "$(id -u)" -f ps --user "$(id -u)" -f
aa_check
} }
# bats test_tags=ps
@test "ps: Get the parent PID of a process" { @test "ps: Get the parent PID of a process" {
ps -o ppid= -p 1 ps -o ppid= -p 1
aa_check
} }
# bats test_tags=ps
@test "ps: Sort processes by memory consumption" { @test "ps: Sort processes by memory consumption" {
ps auxww --sort size ps auxww --sort size
aa_check
} }

View file

@ -5,25 +5,15 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=pstree
@test "pstree: Display a tree of processes" { @test "pstree: Display a tree of processes" {
pstree pstree
aa_check
} }
# bats test_tags=pstree
@test "pstree: Display a tree of processes with PIDs" { @test "pstree: Display a tree of processes with PIDs" {
pstree -p pstree -p
aa_check
} }
# bats test_tags=pstree
@test "pstree: Display all process trees rooted at processes owned by specified user" { @test "pstree: Display all process trees rooted at processes owned by specified user" {
pstree root pstree root
aa_check
} }

View file

@ -5,48 +5,30 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=snap
@test "snap: Search for a package" { @test "snap: Search for a package" {
snap find vim snap find vim
aa_check
} }
# bats test_tags=snap
@test "snap: Install a package" { @test "snap: Install a package" {
sudo snap install nano-strict sudo snap install nano-strict
aa_check
} }
# bats test_tags=snap
@test "snap: Update a package to another channel (track, risk, or branch)" { @test "snap: Update a package to another channel (track, risk, or branch)" {
sudo snap refresh nano-strict --channel=edge sudo snap refresh nano-strict --channel=edge
aa_check
} }
# bats test_tags=snap
@test "snap: Update all packages" { @test "snap: Update all packages" {
sudo snap refresh sudo snap refresh
aa_check
} }
# bats test_tags=snap
@test "snap: Display basic information about installed snap software" { @test "snap: Display basic information about installed snap software" {
sudo snap list sudo snap list
aa_check
} }
# bats test_tags=snap
@test "snap: Check for recent snap changes in the system" { @test "snap: Check for recent snap changes in the system" {
sudo snap changes sudo snap changes
aa_check
} }
# bats test_tags=snap
@test "snap: Uninstall a package" { @test "snap: Uninstall a package" {
sudo snap remove nano-strict sudo snap remove nano-strict
aa_check
} }

View file

@ -5,18 +5,10 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=sync
@test "sync: Flush all pending write operations on all disks" { @test "sync: Flush all pending write operations on all disks" {
sync sync
aa_check
} }
# bats test_tags=sync
@test "sync: Flush all pending write operations on a single file to disk" { @test "sync: Flush all pending write operations on a single file to disk" {
sudo sync / sudo sync /
aa_check
} }

View file

@ -5,19 +5,11 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=systemd-ac-power
@test "systemd-ac-power: Report whether we are connected to an external power source." { @test "systemd-ac-power: Report whether we are connected to an external power source." {
systemd-ac-power || true systemd-ac-power || true
aa_check
} }
# bats test_tags=systemd-ac-power
@test "systemd-ac-power: Check if battery is discharging and low" { @test "systemd-ac-power: Check if battery is discharging and low" {
systemd-ac-power --low || true systemd-ac-power --low || true
aa_check
} }

View file

@ -5,25 +5,16 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=systemd-analyze
@test "systemd-analyze: List all running units, ordered by the time they took to initialize" { @test "systemd-analyze: List all running units, ordered by the time they took to initialize" {
systemd-analyze --no-pager blame systemd-analyze --no-pager blame
aa_check
} }
# bats test_tags=systemd-analyze
@test "systemd-analyze: Print a tree of the time-critical chain of units" { @test "systemd-analyze: Print a tree of the time-critical chain of units" {
systemd-analyze --no-pager critical-chain systemd-analyze --no-pager critical-chain
aa_check
} }
# bats test_tags=systemd-analyze
@test "systemd-analyze: Show security scores of running units" { @test "systemd-analyze: Show security scores of running units" {
systemd-analyze --no-pager security systemd-analyze --no-pager security
aa_check
} }

View file

@ -5,18 +5,10 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=systemd-cat
@test "systemd-cat: Write the output of the specified command to the journal (both output streams are captured)" { @test "systemd-cat: Write the output of the specified command to the journal (both output streams are captured)" {
systemd-cat pwd systemd-cat pwd
aa_check
} }
# bats test_tags=systemd-cat
@test "systemd-cat: Write the output of a pipeline to the journal (`stderr` stays connected to the terminal)" { @test "systemd-cat: Write the output of a pipeline to the journal (`stderr` stays connected to the terminal)" {
echo apparmor.d-test-suite | systemd-cat echo apparmor.d-test-suite | systemd-cat
aa_check
} }

View file

@ -5,25 +5,15 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=systemd-cgls
@test "systemd-cgls: Display the whole control group hierarchy on your system" { @test "systemd-cgls: Display the whole control group hierarchy on your system" {
systemd-cgls --no-pager systemd-cgls --no-pager
aa_check
} }
# bats test_tags=systemd-cgls
@test "systemd-cgls: Display a control group tree of a specific resource controller" { @test "systemd-cgls: Display a control group tree of a specific resource controller" {
systemd-cgls --no-pager io systemd-cgls --no-pager io
aa_check
} }
# bats test_tags=systemd-cgls
@test "systemd-cgls: Display the control group hierarchy of one or more systemd units" { @test "systemd-cgls: Display the control group hierarchy of one or more systemd units" {
systemd-cgls --no-pager --unit systemd-logind systemd-cgls --no-pager --unit systemd-logind
aa_check
} }

View file

@ -3,23 +3,24 @@
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io> # Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-2.0-only
# bats test_tags=systemd-detect-virt load common
@test "systemd-detect-virt: List detectable virtualization technologies" { @test "systemd-detect-virt: List detectable virtualization technologies" {
systemd-detect-virt --list systemd-detect-virt --list
} }
# bats test_tags=systemd-detect-virt # bats test_tags=systemd-detect-virt
@test "systemd-detect-virt: Detect virtualization, print the result and return a zero status code when running in a VM or a container, and a non-zero code otherwise" { @test "systemd-detect-virt: Detect virtualization, print the result and return a zero status code when running in a VM or a container, and a non-zero code otherwise" {
systemd-detect-virt systemd-detect-virt || true
} }
# bats test_tags=systemd-detect-virt # bats test_tags=systemd-detect-virt
@test "systemd-detect-virt: Silently check without printing anything" { @test "systemd-detect-virt: Silently check without printing anything" {
systemd-detect-virt --quiet systemd-detect-virt --quiet || true
} }
# bats test_tags=systemd-detect-virt # bats test_tags=systemd-detect-virt
@test "systemd-detect-virt: Only detect hardware virtualization" { @test "systemd-detect-virt: Only detect hardware virtualization" {
systemd-detect-virt --vm systemd-detect-virt --vm || true
} }

View file

@ -5,31 +5,19 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=systemd-id128
@test "systemd-id128: Generate a new random identifier" { @test "systemd-id128: Generate a new random identifier" {
systemd-id128 new systemd-id128 new
aa_check
} }
# bats test_tags=systemd-id128
@test "systemd-id128: Print the identifier of the current machine" { @test "systemd-id128: Print the identifier of the current machine" {
systemd-id128 machine-id systemd-id128 machine-id
aa_check
} }
# bats test_tags=systemd-id128
@test "systemd-id128: Print the identifier of the current boot" { @test "systemd-id128: Print the identifier of the current boot" {
systemd-id128 boot-id systemd-id128 boot-id
aa_check
} }
# bats test_tags=systemd-id128
@test "systemd-id128: Generate a new random identifier and print it as a UUID (five groups of digits separated by hyphens)" { @test "systemd-id128: Generate a new random identifier and print it as a UUID (five groups of digits separated by hyphens)" {
systemd-id128 new --uuid systemd-id128 new --uuid
aa_check
} }

View file

@ -5,24 +5,14 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=systemd-sysusers
@test "systemd-sysusers: Print the contents of all configuration files (before each file, its name is printed as a comment)" { @test "systemd-sysusers: Print the contents of all configuration files (before each file, its name is printed as a comment)" {
systemd-sysusers --cat-config systemd-sysusers --cat-config
aa_check
} }
# bats test_tags=systemd-sysusers
@test "systemd-sysusers: Process configuration files and print what would be done without actually doing anything" { @test "systemd-sysusers: Process configuration files and print what would be done without actually doing anything" {
systemd-sysusers --dry-run systemd-sysusers --dry-run
aa_check
} }
# bats test_tags=systemd-sysusers
@test "systemd-sysusers: Create users and groups from all configuration file" { @test "systemd-sysusers: Create users and groups from all configuration file" {
sudo systemd-sysusers sudo systemd-sysusers
aa_check
} }

View file

@ -5,55 +5,35 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=uname
@test "uname: Print all information" { @test "uname: Print all information" {
uname --all uname --all
aa_check
} }
# bats test_tags=uname
@test "uname: Print the current kernel name" { @test "uname: Print the current kernel name" {
uname --kernel-name uname --kernel-name
aa_check
} }
# bats test_tags=uname
@test "uname: Print the current network node host name" { @test "uname: Print the current network node host name" {
uname --nodename uname --nodename
aa_check
} }
# bats test_tags=uname
@test "uname: Print the current kernel release" { @test "uname: Print the current kernel release" {
uname --kernel-release uname --kernel-release
aa_check
} }
# bats test_tags=uname
@test "uname: Print the current kernel version" { @test "uname: Print the current kernel version" {
uname --kernel-version uname --kernel-version
aa_check
} }
# bats test_tags=uname
@test "uname: Print the current machine hardware name" { @test "uname: Print the current machine hardware name" {
uname --machine uname --machine
aa_check
} }
# bats test_tags=uname
@test "uname: Print the current processor type" { @test "uname: Print the current processor type" {
uname --processor uname --processor
aa_check
} }
# bats test_tags=uname
@test "uname: Print the current operating system name" { @test "uname: Print the current operating system name" {
uname --operating-system uname --operating-system
aa_check
} }

View file

@ -5,25 +5,15 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=upower
@test "upower: Display power and battery information" { @test "upower: Display power and battery information" {
upower --dump upower --dump
aa_check
} }
# bats test_tags=upower
@test "upower: List all power devices" { @test "upower: List all power devices" {
upower --enumerate upower --enumerate
aa_check
} }
# bats test_tags=upower
@test "upower: Display version" { @test "upower: Display version" {
upower --version upower --version
aa_check
} }

View file

@ -5,31 +5,19 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=uptime
@test "uptime: Print current time, uptime, number of logged-in users and other information" { @test "uptime: Print current time, uptime, number of logged-in users and other information" {
uptime uptime
aa_check
} }
# bats test_tags=uptime
@test "uptime: Show only the amount of time the system has been booted for" { @test "uptime: Show only the amount of time the system has been booted for" {
uptime --pretty uptime --pretty
aa_check
} }
# bats test_tags=uptime
@test "uptime: Print the date and time the system booted up at" { @test "uptime: Print the date and time the system booted up at" {
uptime --since uptime --since
aa_check
} }
# bats test_tags=uptime
@test "uptime: Display version" { @test "uptime: Display version" {
uptime --version uptime --version
aa_check
} }

View file

@ -5,45 +5,28 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=useradd
@test "useradd: Create a new user with the specified shell" { @test "useradd: Create a new user with the specified shell" {
sudo useradd --shell /bin/bash --create-home user2 sudo useradd --shell /bin/bash --create-home user2
aa_check
} }
# bats test_tags=useradd
@test "useradd: Create a new user with the specified user ID" { @test "useradd: Create a new user with the specified user ID" {
sudo useradd --uid 3000 user3 sudo useradd --uid 3000 user3
aa_check
} }
# bats test_tags=useradd
@test "useradd: Create a new user belonging to additional groups (mind the lack of whitespace)" { @test "useradd: Create a new user belonging to additional groups (mind the lack of whitespace)" {
sudo useradd --groups adm user4 sudo useradd --groups adm user4
aa_check
} }
# bats test_tags=useradd
@test "useradd: Create a new system user without the home directory" { @test "useradd: Create a new system user without the home directory" {
sudo useradd --system sys2 sudo useradd --system sys2
aa_check
} }
# bats test_tags=userdel
@test "userdel: Remove a user" { @test "userdel: Remove a user" {
sudo userdel user3 sudo userdel user3
sudo userdel user4 sudo userdel user4
sudo userdel sys2 sudo userdel sys2
aa_check
} }
# bats test_tags=userdel
@test "userdel: Remove a user along with the home directory and mail spool" { @test "userdel: Remove a user along with the home directory and mail spool" {
sudo userdel --remove user2 sudo userdel --remove user2
aa_check
} }

View file

@ -5,37 +5,23 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=userdbctl
@test "userdbctl: List all known user records" { @test "userdbctl: List all known user records" {
userdbctl --no-pager user userdbctl --no-pager user
aa_check
} }
# bats test_tags=userdbctl
@test "userdbctl: Show details of a specific user" { @test "userdbctl: Show details of a specific user" {
userdbctl --no-pager user "$USER" userdbctl --no-pager user "$USER"
aa_check
} }
# bats test_tags=userdbctl
@test "userdbctl: List all known groups" { @test "userdbctl: List all known groups" {
userdbctl --no-pager group userdbctl --no-pager group
aa_check
} }
# bats test_tags=userdbctl
@test "userdbctl: Show details of a specific group" { @test "userdbctl: Show details of a specific group" {
sudo userdbctl --no-pager group "$USER" sudo userdbctl --no-pager group "$USER"
aa_check
} }
# bats test_tags=userdbctl
@test "userdbctl: List all services currently providing user/group definitions to the system" { @test "userdbctl: List all services currently providing user/group definitions to the system" {
userdbctl --no-pager services userdbctl --no-pager services
aa_check
} }

View file

@ -5,19 +5,11 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=users
@test "users: Print logged in usernames" { @test "users: Print logged in usernames" {
users users
aa_check
} }
# bats test_tags=users
@test "users: Print logged in usernames according to a given file" { @test "users: Print logged in usernames according to a given file" {
users /var/log/wmtp users /var/log/wmtp
aa_check
} }

View file

@ -5,25 +5,14 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=uuidd
@test "uuidd: Generate a random UUID" { @test "uuidd: Generate a random UUID" {
uuidd --random uuidd --random
aa_check
} }
# bats test_tags=uuidd
@test "uuidd: Generate a bulk number of random UUIDs" { @test "uuidd: Generate a bulk number of random UUIDs" {
uuidd --random --uuids 10 uuidd --random --uuids 10
aa_check
} }
# bats test_tags=uuidd
@test "uuidd: Generate a time-based UUID, based on the current time and MAC address of the system" { @test "uuidd: Generate a time-based UUID, based on the current time and MAC address of the system" {
uuidd --time uuidd --time
aa_check
} }

View file

@ -5,19 +5,10 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=uuidgen
@test "uuidgen: Create a random UUIDv4" { @test "uuidgen: Create a random UUIDv4" {
uuidgen --random uuidgen --random
aa_check
} }
# bats test_tags=uuidgen
@test "uuidgen: Create a UUIDv1 based on the current time" { @test "uuidgen: Create a UUIDv1 based on the current time" {
uuidgen --time uuidgen --time
aa_check
} }

View file

@ -5,18 +5,10 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=w
@test "w: Display information about all users who are currently logged in" { @test "w: Display information about all users who are currently logged in" {
w w
aa_check
} }
# bats test_tags=w
@test "w: Display information about a specific user" { @test "w: Display information about a specific user" {
w root w root
aa_check
} }

View file

@ -5,25 +5,15 @@
load common load common
setup_file() {
aa_setup
}
# bats test_tags=who
@test "who: Display the username, line, and time of all currently logged-in sessions" { @test "who: Display the username, line, and time of all currently logged-in sessions" {
who who
aa_check
} }
# bats test_tags=who
@test "who: Display all available information" { @test "who: Display all available information" {
who -a who -a
aa_check
} }
# bats test_tags=who
@test "who: Display all available information with table headers" { @test "who: Display all available information with table headers" {
who -a -H who -a -H
aa_check
} }

View file

@ -68,7 +68,6 @@ func run() error {
if err != nil { if err != nil {
return err return err
} }
tests = tests.Filter()
if err := cfg.BatsDir.RemoveAll(); err != nil { if err := cfg.BatsDir.RemoveAll(); err != nil {
return err return err
@ -76,6 +75,12 @@ func run() error {
if err := cfg.BatsDir.MkdirAll(); err != nil { if err := cfg.BatsDir.MkdirAll(); err != nil {
return err return err
} }
if err := cfg.BatsDir.Join("profiled").MkdirAll(); err != nil {
return err
}
if err := cfg.BatsDir.Join("unprofiled").MkdirAll(); err != nil {
return err
}
for _, test := range tests { for _, test := range tests {
if err := test.Write(cfg.BatsDir); err != nil { if err := test.Write(cfg.BatsDir); err != nil {
return err return err

View file

@ -20,16 +20,10 @@ const tmplTest = `#!/usr/bin/env bats
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-2.0-only
load common load common
setup_file() {
aa_setup
}
{{ $name := .Name -}} {{ $name := .Name -}}
{{ range .Commands }} {{ range .Commands }}
# bats test_tags={{ $name }}
@test "{{ $name }}: {{ .Description }}" { @test "{{ $name }}: {{ .Description }}" {
{{ .Cmd }} {{ .Cmd }}
aa_check
} }
{{ end }} {{ end }}
` `
@ -77,13 +71,14 @@ func (t Test) IsInstalled() bool {
} }
func (t Test) Write(dir *paths.Path) error { func (t Test) Write(dir *paths.Path) error {
dstDir := dir.Join("profiled")
if !t.HasProfile() { if !t.HasProfile() {
return nil dstDir = dir.Join("unprofiled")
} }
path := dstDir.Join(t.Name + ".bats")
path := dir.Join(t.Name + ".bats")
if paths.New("tests/bats").Join(t.Name + ".bats").Exist() { if paths.New("tests/bats").Join(t.Name + ".bats").Exist() {
path = dir.Join("00." + t.Name + ".bats") path = dstDir.Join("00." + t.Name + ".bats")
} }
content := renderBatsFile(t) content := renderBatsFile(t)
if err := path.WriteFile([]byte(content)); err != nil { if err := path.WriteFile([]byte(content)); err != nil {