summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2022-11-09 16:17:41 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2022-11-09 16:45:43 +0100
commit44bdb55ce2a8d835c18028fc47bac647f8b2fa96 (patch)
treeb7acebf90d921615164c5c533b3076f5a2392f6d /tests
parent5eb8b1ae7c5f5d1ec8de2c17ede97b54a66f52e8 (diff)
downloadalpine-conf-44bdb55ce2a8d835c18028fc47bac647f8b2fa96.zip
setup-disk: refactor and test find_disks
Diffstat (limited to 'tests')
-rwxr-xr-xtests/setup_disk_test50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/setup_disk_test b/tests/setup_disk_test
index c3af040..65b7ada 100755
--- a/tests/setup_disk_test
+++ b/tests/setup_disk_test
@@ -5,6 +5,7 @@ init_tests \
setup_disk_usage \
setup_disk_mode_none \
setup_disk_none \
+ setup_disk_func_find_disks
setup_disk_usage_body() {
test_usage setup-disk
@@ -22,3 +23,52 @@ setup_disk_none_body() {
setup-disk none
}
+fake_disk() {
+ mkdir -p sys/block/$1/device \
+ sys/block/$1/holders
+}
+
+fake_partition() {
+ mkdir -p sys/block/$1/$1$2/holders
+}
+
+fake_mount() {
+ mkdir -p proc
+ echo "$1" >> proc/mounts
+}
+
+fake_raid() {
+ local md="$1"
+ shift
+ for dev; do
+ for p in sys/block/*/$dev/holders sys/block/$dev/holders; do
+ if [ -d "$p" ]; then
+ touch "$p"/$md
+ fi
+ done
+ done
+}
+
+setup_disk_func_find_disks_body() {
+ init_env
+ fake_disk vda
+ fake_disk vdb
+ fake_partition vdb 1
+ fake_disk sda
+ fake_disk nvme0n1
+ fake_partition nvme0n1 p2
+
+ # simulate vda and vdb1 being part of md0 raid
+ fake_raid md0 vda vdb1
+
+ # simulate nvme0n1p2 being mounted
+ fake_mount '/dev/nvme0n1p2 /boot vfat rw,relatime,fmask=0022 0 0'
+
+ SETUP_DISK_TESTFUNC=find_disks USE_RAID=1 \
+ atf_check -s exit:0 \
+ -o match:"^ sda$" \
+ -e match:"vda is part of a running raid" \
+ -e match:"vdb is part of a running raid" \
+ setup-disk
+}
+