summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2023-01-25 16:22:11 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2023-01-25 16:24:47 +0100
commitfe3f23437a5d8534b2c64a39c430d366de3e6387 (patch)
treed043dce0299f569c331b08fee95e0501fad2df6d
parent6500eff2a2818c2f50b185e1df7f50b962bda9a5 (diff)
downloadalpine-conf-fe3f23437a5d8534b2c64a39c430d366de3e6387.zip
tests: add tests for setup-disk's uuid_or_device
also add a convenience function to create fake binaries.
-rwxr-xr-xtests/setup_disk_test31
-rw-r--r--tests/test_env.sh7
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/setup_disk_test b/tests/setup_disk_test
index d7951ea..b3c714a 100755
--- a/tests/setup_disk_test
+++ b/tests/setup_disk_test
@@ -9,6 +9,7 @@ init_tests \
setup_disk_func_setup_partitions_dos \
setup_disk_func_setup_partitions_gpt \
setup_disk_func_find_efi_size \
+ setup_disk_func_uuid_or_device \
setup_disk_non_existing_block_dev \
setup_disk_install_mounted_root_nvme \
setup_disk_install_mounted_root_efi_boot
@@ -192,6 +193,36 @@ setup_disk_func_find_efi_size_body() {
done
}
+setup_disk_func_uuid_or_device_body() {
+ init_env
+ fake_bin blkid <<-EOF
+ #!/bin/sh
+ cat <<-EOF2
+ /dev/sda3: UUID="4ec0992a-bf5a-4d04-bc49-06c131ae901b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0ce794d3-03"
+ /dev/sda1: UUID="1db12961-31ce-420f-94f0-559a1f6592ff" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="0ce794d3-01"
+ /dev/sda2: UUID="a5fbbd70-94f6-4d03-947c-e3afb91a32c8" TYPE="swap" PARTUUID="0ce794d3-02"
+ /dev/md0: UUID="86a00eb9-9b5a-4d73-812c-8fc958673a7c" TYPE="LVM2_member"
+ EOF2
+ EOF
+
+ SETUP_DISK_TESTFUNC=uuid_or_device \
+ atf_check -s exit:0 \
+ -o match:"/dev/vda1" \
+ setup-disk /dev/vda1
+
+ SETUP_DISK_TESTFUNC=uuid_or_device \
+ atf_check -s exit:0 \
+ -o not-match:"UUID=" \
+ -o match:"/dev/md0" \
+ setup-disk /dev/md0
+
+ SETUP_DISK_TESTFUNC=uuid_or_device \
+ atf_check -s exit:0 \
+ -o match:"UUID=1db12961-31ce-420f-94f0-559a1f6592ff" \
+ setup-disk /dev/sda1
+
+}
+
setup_disk_non_existing_block_dev_body() {
init_env
atf_check -s not-exit:0 \
diff --git a/tests/test_env.sh b/tests/test_env.sh
index 57fd09f..c74f9d1 100644
--- a/tests/test_env.sh
+++ b/tests/test_env.sh
@@ -4,6 +4,13 @@ init_env() {
export ROOT=$PWD LIBDIR=$(atf_get_srcdir)/.. MOCK=echo
}
+fake_bin() {
+ mkdir -p bin
+ cat > bin/"$1"
+ chmod +x bin/"$1"
+ PATH="$PWD/bin:$PATH"
+}
+
init_tests() {
TESTS="$@"
export TESTS