Skip to content

Commit 415f596

Browse files
committed
patch tests
1 parent 6020b9b commit 415f596

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

tests/fixtures/setup-test-env.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,17 @@ create_mount_point() {
128128

129129
# Export test configuration
130130
export_test_config() {
131+
local loop_dev=$1
131132
local config_file="/tmp/test_env.conf"
132133

134+
# Get UUID of the loop device (for unlock_device function)
135+
local loop_uuid
136+
loop_uuid=$(blkid -s UUID -o value "$loop_dev")
137+
138+
# Get UUID of the LVM logical volume (for mount tests)
139+
local lv_uuid
140+
lv_uuid=$(blkid -s UUID -o value "/dev/$TEST_VG_NAME/$TEST_LV_NAME")
141+
133142
cat > "$config_file" <<EOF
134143
# Test environment configuration
135144
export TEST_LUKS_NAME="$TEST_LUKS_NAME"
@@ -139,9 +148,15 @@ export TEST_MOUNT_POINT="$TEST_MOUNT_POINT"
139148
export TEST_PASSWORD="$TEST_PASSWORD"
140149
export TEST_LUKS_DEV="/dev/mapper/$TEST_LUKS_NAME"
141150
export TEST_LV_DEV="/dev/$TEST_VG_NAME/$TEST_LV_NAME"
151+
export TEST_LOOP_UUID="$loop_uuid"
152+
export TEST_LV_UUID="$lv_uuid"
153+
export TEST_LUKS_MAPPER="$TEST_LUKS_NAME"
154+
export TEST_LV_MAPPER="$TEST_VG_NAME-$TEST_LV_NAME"
142155
EOF
143156

144157
log_info "Test configuration exported to $config_file"
158+
log_info " Loop device UUID: $loop_uuid"
159+
log_info " LV UUID: $lv_uuid"
145160
log_info "Source with: source $config_file"
146161
}
147162

@@ -152,11 +167,12 @@ main() {
152167
check_privileges
153168
install_dependencies
154169

155-
local loop_dev=$(create_loop_device)
170+
local loop_dev
171+
loop_dev=$(create_loop_device)
156172
create_luks_container "$loop_dev"
157173
create_lvm_on_luks
158174
create_mount_point
159-
export_test_config
175+
export_test_config "$loop_dev"
160176

161177
log_info "Test environment setup complete!"
162178
log_info ""

tests/integration/test-luks.sh

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,31 @@ run_test() {
5151
test_luks_lock_unlock() {
5252
run_test "LUKS lock and unlock"
5353

54-
# Get loop device for LUKS container
55-
local loop_dev=$(losetup -j /tmp/test_loop.img | cut -d: -f1)
56-
57-
# Close LUKS
58-
if lock_device "$TEST_LUKS_NAME"; then
54+
if lock_device "$TEST_LUKS_MAPPER" "luks"; then
5955
log_pass "Successfully closed LUKS container"
6056
else
6157
log_fail "Failed to close LUKS container"
6258
return 1
6359
fi
6460

6561
# Verify it's closed
66-
if [[ ! -e "/dev/mapper/$TEST_LUKS_NAME" ]]; then
62+
if [[ ! -e "/dev/mapper/$TEST_LUKS_MAPPER" ]]; then
6763
log_pass "LUKS container is closed"
6864
else
6965
log_fail "LUKS container still exists after close"
7066
return 1
7167
fi
7268

73-
# Reopen LUKS
74-
if echo -n "$TEST_PASSWORD" | unlock_device "$loop_dev" "$TEST_LUKS_NAME" "luks"; then
69+
# Reopen LUKS using UUID
70+
if echo -n "$TEST_PASSWORD" | unlock_device "$TEST_LOOP_UUID" "$TEST_LUKS_MAPPER" "none" "luks"; then
7571
log_pass "Successfully reopened LUKS container"
7672
else
7773
log_fail "Failed to reopen LUKS container"
7874
return 1
7975
fi
8076

8177
# Verify it's open
82-
if [[ -e "/dev/mapper/$TEST_LUKS_NAME" ]]; then
78+
if [[ -e "/dev/mapper/$TEST_LUKS_MAPPER" ]]; then
8379
log_pass "LUKS container is open"
8480
else
8581
log_fail "LUKS container does not exist after open"
@@ -91,41 +87,38 @@ test_luks_lock_unlock() {
9187
test_luks_wrong_password() {
9288
run_test "LUKS wrong password handling"
9389

94-
local loop_dev=$(losetup -j /tmp/test_loop.img | cut -d: -f1)
95-
9690
# Close first
97-
lock_device "$TEST_LUKS_NAME" &>/dev/null
91+
lock_device "$TEST_LUKS_MAPPER" "luks" &>/dev/null
9892

9993
# Try to open with wrong password
100-
if echo -n "wrongpassword" | unlock_device "$loop_dev" "$TEST_LUKS_NAME" "luks" 2>/dev/null; then
94+
if echo -n "wrongpassword" | unlock_device "$TEST_LOOP_UUID" "$TEST_LUKS_MAPPER" "none" "luks" 2>/dev/null; then
10195
log_fail "LUKS opened with wrong password (should have failed)"
10296
return 1
10397
else
10498
log_pass "LUKS correctly rejected wrong password"
10599
fi
106100

107101
# Reopen with correct password for subsequent tests
108-
echo -n "$TEST_PASSWORD" | unlock_device "$loop_dev" "$TEST_LUKS_NAME" "luks" &>/dev/null
102+
echo -n "$TEST_PASSWORD" | unlock_device "$TEST_LOOP_UUID" "$TEST_LUKS_MAPPER" "none" "luks" &>/dev/null
109103
}
110104

111105
# Test 3: Double close handling
112106
test_luks_double_close() {
113107
run_test "LUKS double close handling"
114108

115109
# Close once
116-
lock_device "$TEST_LUKS_NAME" &>/dev/null
110+
lock_device "$TEST_LUKS_MAPPER" "luks" &>/dev/null
117111

118-
# Try to close again
119-
if lock_device "$TEST_LUKS_NAME" 2>/dev/null; then
112+
# Try to close again (library should skip if already closed)
113+
if lock_device "$TEST_LUKS_MAPPER" "luks" 2>/dev/null; then
120114
log_pass "Double close handled gracefully"
121115
else
122116
log_fail "Double close returned error"
123117
return 1
124118
fi
125119

126120
# Reopen for subsequent tests
127-
local loop_dev=$(losetup -j /tmp/test_loop.img | cut -d: -f1)
128-
echo -n "$TEST_PASSWORD" | unlock_device "$loop_dev" "$TEST_LUKS_NAME" "luks" &>/dev/null
121+
echo -n "$TEST_PASSWORD" | unlock_device "$TEST_LOOP_UUID" "$TEST_LUKS_MAPPER" "none" "luks" &>/dev/null
129122
}
130123

131124
# Run all tests

tests/integration/test-lvm.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ run_test() {
5151
test_lvm_verify() {
5252
run_test "LVM verification"
5353

54-
if verify_lvm "$TEST_VG_NAME" "$TEST_LV_NAME"; then
54+
if verify_lvm "$TEST_LV_NAME" "$TEST_VG_NAME"; then
5555
log_pass "LVM verification successful"
5656
else
5757
log_fail "LVM verification failed"
@@ -63,7 +63,7 @@ test_lvm_verify() {
6363
test_lvm_is_active() {
6464
run_test "LVM active check"
6565

66-
if lvm_is_active "$TEST_VG_NAME" "$TEST_LV_NAME"; then
66+
if lvm_is_active "$TEST_LV_NAME" "$TEST_VG_NAME"; then
6767
log_pass "LVM is active"
6868
else
6969
log_fail "LVM is not active"
@@ -76,31 +76,31 @@ test_lvm_deactivate_activate() {
7676
run_test "LVM deactivate and reactivate"
7777

7878
# Deactivate
79-
if deactivate_lvm "$TEST_VG_NAME" "$TEST_LV_NAME"; then
79+
if deactivate_lvm "$TEST_LV_NAME" "$TEST_VG_NAME"; then
8080
log_pass "Successfully deactivated LVM"
8181
else
8282
log_fail "Failed to deactivate LVM"
8383
return 1
8484
fi
8585

8686
# Verify it's inactive
87-
if ! lvm_is_active "$TEST_VG_NAME" "$TEST_LV_NAME"; then
87+
if ! lvm_is_active "$TEST_LV_NAME" "$TEST_VG_NAME"; then
8888
log_pass "LVM is inactive"
8989
else
9090
log_fail "LVM is still active after deactivation"
9191
return 1
9292
fi
9393

9494
# Reactivate
95-
if activate_lvm "$TEST_VG_NAME" "$TEST_LV_NAME"; then
95+
if activate_lvm "$TEST_LV_NAME" "$TEST_VG_NAME"; then
9696
log_pass "Successfully reactivated LVM"
9797
else
9898
log_fail "Failed to reactivate LVM"
9999
return 1
100100
fi
101101

102102
# Verify it's active
103-
if lvm_is_active "$TEST_VG_NAME" "$TEST_LV_NAME"; then
103+
if lvm_is_active "$TEST_LV_NAME" "$TEST_VG_NAME"; then
104104
log_pass "LVM is active after reactivation"
105105
else
106106
log_fail "LVM is not active after reactivation"
@@ -113,25 +113,25 @@ test_lvm_double_deactivate() {
113113
run_test "LVM double deactivation handling"
114114

115115
# Deactivate once
116-
deactivate_lvm "$TEST_VG_NAME" "$TEST_LV_NAME" &>/dev/null
116+
deactivate_lvm "$TEST_LV_NAME" "$TEST_VG_NAME" &>/dev/null
117117

118118
# Try to deactivate again
119-
if deactivate_lvm "$TEST_VG_NAME" "$TEST_LV_NAME" 2>/dev/null; then
119+
if deactivate_lvm "$TEST_LV_NAME" "$TEST_VG_NAME" 2>/dev/null; then
120120
log_pass "Double deactivation handled gracefully"
121121
else
122122
log_fail "Double deactivation returned error"
123123
return 1
124124
fi
125125

126126
# Reactivate for subsequent tests
127-
activate_lvm "$TEST_VG_NAME" "$TEST_LV_NAME" &>/dev/null
127+
activate_lvm "$TEST_LV_NAME" "$TEST_VG_NAME" &>/dev/null
128128
}
129129

130130
# Test 5: Verify nonexistent VG/LV
131131
test_lvm_verify_nonexistent() {
132132
run_test "LVM verify nonexistent volume"
133133

134-
if verify_lvm "nonexistent_vg" "nonexistent_lv" 2>/dev/null; then
134+
if verify_lvm "nonexistent_lv" "nonexistent_vg" 2>/dev/null; then
135135
log_fail "verify_lvm succeeded for nonexistent volume (should fail)"
136136
return 1
137137
else

tests/integration/test-mount.sh

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,21 @@ run_test() {
5151
test_mount_unmount() {
5252
run_test "Mount and unmount device"
5353

54-
# Mount
55-
if mount_device "$TEST_LV_DEV" "$TEST_MOUNT_POINT" "none"; then
54+
if mount_device "$TEST_LV_MAPPER" "$TEST_MOUNT_POINT" "defaults"; then
5655
log_pass "Successfully mounted device"
5756
else
5857
log_fail "Failed to mount device"
5958
return 1
6059
fi
6160

6261
# Verify it's mounted
63-
if mountpoint -q "$TEST_MOUNT_POINT"; then
62+
if mountpoint -q "/mnt/$TEST_MOUNT_POINT"; then
6463
log_pass "Device is mounted"
6564
else
6665
log_fail "Device is not mounted"
6766
return 1
6867
fi
6968

70-
# Unmount
7169
if unmount_device "$TEST_MOUNT_POINT"; then
7270
log_pass "Successfully unmounted device"
7371
else
@@ -76,7 +74,7 @@ test_mount_unmount() {
7674
fi
7775

7876
# Verify it's unmounted
79-
if ! mountpoint -q "$TEST_MOUNT_POINT"; then
77+
if ! mountpoint -q "/mnt/$TEST_MOUNT_POINT"; then
8078
log_pass "Device is unmounted"
8179
else
8280
log_fail "Device is still mounted"
@@ -88,11 +86,10 @@ test_mount_unmount() {
8886
test_mount_write_read() {
8987
run_test "Mount, write, unmount, remount, read"
9088

91-
local test_file="$TEST_MOUNT_POINT/test_file.txt"
89+
local test_file="/mnt/$TEST_MOUNT_POINT/test_file.txt"
9290
local test_content="Hello from integration tests!"
9391

94-
# Mount
95-
mount_device "$TEST_LV_DEV" "$TEST_MOUNT_POINT" "none" &>/dev/null
92+
mount_device "$TEST_LV_MAPPER" "$TEST_MOUNT_POINT" "defaults" &>/dev/null
9693

9794
# Write test file
9895
if echo "$test_content" > "$test_file"; then
@@ -102,15 +99,15 @@ test_mount_write_read() {
10299
return 1
103100
fi
104101

105-
# Unmount
106102
unmount_device "$TEST_MOUNT_POINT" &>/dev/null
107103

108104
# Remount
109-
mount_device "$TEST_LV_DEV" "$TEST_MOUNT_POINT" "none" &>/dev/null
105+
mount_device "$TEST_LV_MAPPER" "$TEST_MOUNT_POINT" "defaults" &>/dev/null
110106

111107
# Read and verify
112108
if [[ -f "$test_file" ]]; then
113-
local read_content=$(cat "$test_file")
109+
local read_content
110+
read_content=$(cat "$test_file")
114111
if [[ "$read_content" == "$test_content" ]]; then
115112
log_pass "Successfully read test file with correct content"
116113
else
@@ -132,10 +129,10 @@ test_double_mount() {
132129
run_test "Double mount handling"
133130

134131
# Mount once
135-
mount_device "$TEST_LV_DEV" "$TEST_MOUNT_POINT" "none" &>/dev/null
132+
mount_device "$TEST_LV_MAPPER" "$TEST_MOUNT_POINT" "defaults" &>/dev/null
136133

137-
# Try to mount again
138-
if mount_device "$TEST_LV_DEV" "$TEST_MOUNT_POINT" "none" 2>/dev/null; then
134+
# Try to mount again (library should skip if already mounted)
135+
if mount_device "$TEST_LV_MAPPER" "$TEST_MOUNT_POINT" "defaults" 2>/dev/null; then
139136
log_pass "Double mount handled gracefully"
140137
else
141138
log_fail "Double mount returned error"
@@ -152,12 +149,12 @@ test_double_unmount() {
152149
run_test "Double unmount handling"
153150

154151
# Mount first
155-
mount_device "$TEST_LV_DEV" "$TEST_MOUNT_POINT" "none" &>/dev/null
152+
mount_device "$TEST_LV_MAPPER" "$TEST_MOUNT_POINT" "defaults" &>/dev/null
156153

157154
# Unmount once
158155
unmount_device "$TEST_MOUNT_POINT" &>/dev/null
159156

160-
# Try to unmount again
157+
# Try to unmount again (library should skip if not mounted)
161158
if unmount_device "$TEST_MOUNT_POINT" 2>/dev/null; then
162159
log_pass "Double unmount handled gracefully"
163160
else
@@ -166,24 +163,24 @@ test_double_unmount() {
166163
fi
167164
}
168165

169-
# Test 5: Mount with "none" UUID
170-
test_mount_none_uuid() {
171-
run_test "Mount with UUID='none'"
166+
# Test 5: Mount with "none" device handling
167+
test_mount_none_device() {
168+
run_test "Mount with device='none'"
172169

173-
# Try to mount with "none" UUID
174-
if mount_device "none" "$TEST_MOUNT_POINT" "none"; then
175-
log_pass "mount_device with 'none' UUID handled correctly"
170+
# Mount with "none" device (library should skip)
171+
if mount_device "none" "test_none" "defaults"; then
172+
log_pass "mount_device with 'none' device handled correctly"
176173
else
177-
log_fail "mount_device with 'none' UUID returned error"
174+
log_fail "mount_device with 'none' device returned error"
178175
return 1
179176
fi
180177

181178
# Verify nothing was actually mounted
182-
if ! mountpoint -q "$TEST_MOUNT_POINT"; then
183-
log_pass "Nothing mounted for 'none' UUID"
179+
if ! mountpoint -q "/mnt/test_none"; then
180+
log_pass "Nothing mounted for 'none' device"
184181
else
185-
log_fail "Something was mounted for 'none' UUID"
186-
unmount_device "$TEST_MOUNT_POINT" &>/dev/null
182+
log_fail "Something was mounted for 'none' device"
183+
unmount_device "test_none" &>/dev/null
187184
return 1
188185
fi
189186
}
@@ -199,7 +196,7 @@ main() {
199196
test_mount_write_read
200197
test_double_mount
201198
test_double_unmount
202-
test_mount_none_uuid
199+
test_mount_none_device
203200

204201
echo ""
205202
echo "========================================="

0 commit comments

Comments
 (0)