2021-02-26 22:19:36 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function test_partitioning()
|
|
|
|
{
|
|
|
|
local img
|
2021-02-28 09:22:13 +01:00
|
|
|
local test_version=20210228
|
|
|
|
local min_version=20210101
|
|
|
|
local max_version=20211231
|
|
|
|
|
2021-02-26 22:19:36 +01:00
|
|
|
img=$(mktemp -u)
|
2021-02-26 22:41:37 +01:00
|
|
|
dd if=/dev/zero of="$img" bs=1M seek=16384 count=0 2> /dev/null
|
2021-02-28 09:22:13 +01:00
|
|
|
|
2021-02-26 22:36:16 +01:00
|
|
|
setup_drive "$img"
|
2021-02-26 22:46:54 +01:00
|
|
|
output=$(parted -ms "$img" -- print)
|
2021-02-26 22:41:37 +01:00
|
|
|
sed -i "s|T_E_M_P|$img|g;" tests/data/parted.dat
|
2021-02-28 09:40:32 +01:00
|
|
|
assertEquals "setup_drive" "$(cat tests/data/parted.dat)" "$output"
|
2021-02-28 09:22:13 +01:00
|
|
|
|
2021-03-02 12:12:10 +01:00
|
|
|
rename_partition "$img" 2 "root_$test_version"
|
2021-02-26 22:41:37 +01:00
|
|
|
output=$(parted -ms "$img" -- print)
|
2021-02-26 22:46:54 +01:00
|
|
|
sed -i "s|T_E_M_P|$img|g;" tests/data/rename.dat
|
2021-02-28 09:40:32 +01:00
|
|
|
assertEquals "rename_partition" "$(cat tests/data/rename.dat)" "$output"
|
2021-02-28 09:22:13 +01:00
|
|
|
|
|
|
|
version_from_partnum "$img" 2
|
2021-02-28 09:48:57 +01:00
|
|
|
assertEquals "version_from_partnum 2" "$test_version" "$version"
|
2021-02-28 09:22:13 +01:00
|
|
|
|
|
|
|
find_unused "$img"
|
2021-02-28 09:40:32 +01:00
|
|
|
assertEquals "find_unused" 3 "$unused"
|
2021-02-28 10:06:46 +01:00
|
|
|
version_from_partnum "$img" 3
|
|
|
|
assertEquals "version_from_partnum unused" "" "$version"
|
2021-02-28 09:22:13 +01:00
|
|
|
|
2021-03-02 12:12:10 +01:00
|
|
|
rename_partition "$img" 3 "root_$min_version"
|
2021-02-28 09:22:13 +01:00
|
|
|
find_oldest "$img"
|
2021-02-28 09:58:49 +01:00
|
|
|
assertEquals "find_oldest" 3 "$oldest"
|
2021-02-28 09:40:32 +01:00
|
|
|
version_from_partnum "$img" 3
|
|
|
|
assertEquals "version_from partnum 3" "$min_version" "$version"
|
2021-02-28 09:22:13 +01:00
|
|
|
|
2021-03-02 12:12:10 +01:00
|
|
|
rename_partition "$img" 4 "root_$max_version"
|
2021-02-28 09:22:13 +01:00
|
|
|
find_newest "$img"
|
2021-02-28 09:58:49 +01:00
|
|
|
assertEquals "find_newest" 4 "$newest"
|
2021-02-28 09:40:32 +01:00
|
|
|
version_from_partnum "$img" 4
|
|
|
|
assertEquals "version_from_partnum 4" "$max_version" "$version"
|
2021-02-28 09:22:13 +01:00
|
|
|
|
2021-02-28 09:28:37 +01:00
|
|
|
partition_list "$img"
|
2021-02-28 09:40:32 +01:00
|
|
|
assertEquals "partition_list" "1 2 3 4 5" "$partitions"
|
2021-02-28 09:22:13 +01:00
|
|
|
|
2021-02-26 22:19:36 +01:00
|
|
|
rm -f "$img"
|
|
|
|
}
|
|
|
|
|
|
|
|
function oneTimeSetUp()
|
|
|
|
{
|
|
|
|
. drive.inc
|
|
|
|
}
|
|
|
|
|
|
|
|
# Load shUnit2.
|
|
|
|
. /usr/bin/shunit2
|