Skip to content

Commit 34a4cf2

Browse files
committed
Add tests for ext4
1 parent 352b999 commit 34a4cf2

File tree

5 files changed

+128
-50
lines changed

5 files changed

+128
-50
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,26 @@ go mod tidy
2121
```
2222

2323
## Test
24+
TODO:
25+
- check if xfs bug manifests after fallocate
26+
- check if xfs bug manifests via docker containers
27+
- check if '-o nouuid' works with ext4
28+
- add '-o nouuid'
29+
- add test that volume can be remounted after adding some data
30+
31+
create sparse ext4 volume of 1GiB on a 100 MiB disk - success
32+
create regular ext4 volume of 1GiB on a 100 Mib disk - fail
33+
34+
create sparse xfs volume of 1GiB on a 100 MiB disk - success
35+
create regular xfs volume of 1GiB on a 100 MiB disk - fail
36+
2437
on ext4/xfs vs ext3
25-
not enough space
38+
39+
not enough space - data file should be cleaned up
40+
41+
uid/gid - default & custom
42+
43+
mode - default & custom
44+
45+
inspect - should export status fields
46+

tests/test.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
IMAGE="alpine"
66
DRIVER="docker-volume-loopback"
7+
DATA_DIR="/var/lib/${DRIVER}"
78

8-
#random () {
9-
# echo "$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1)"
10-
#}
119

12-
#VOLUME="$(random)"
10+
setUp() {
11+
HANDLE=$(mktemp -u)
12+
truncate -s "${1:-2GiB}" "${HANDLE}"
13+
mkfs.xfs "${HANDLE}" &> /dev/null
14+
mount -o nouuid "${HANDLE}" "${DATA_DIR}"
15+
}
1316

14-
. ./shunit2
17+
tearDown() {
18+
umount -ld "${DATA_DIR}"
19+
rm -f "${HANDLE}"
20+
}
21+
22+
. ./shunit2

tests/test_disk_space_limits.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
#!/usr/bin/env bash
22

3-
oneTimeSetUp() {
4-
export VOLUME_DEFAULT=$(docker volume create -d "${DRIVER}")
5-
export VOLUME_CUSTOM=$(docker volume create -d "${DRIVER}" -o size=100Mi)
6-
}
7-
8-
9-
oneTimeTearDown() {
10-
docker volume rm "${VOLUME_DEFAULT}" "${VOLUME_CUSTOM}" > /dev/null
11-
}
12-
133
testDefaultVolumeSize() {
14-
size=$(docker run --rm -it -v "${VOLUME_DEFAULT}:/srv" "${IMAGE}" df -m /srv | tail -1 | awk '{print $2}')
4+
local volume size
5+
# setup
6+
volume=$(docker volume create -d "${DRIVER}")
7+
local size=$(docker run --rm -it -v "${volume}:/srv" "${IMAGE}" df -m /srv | tail -1 | awk '{print $2}')
8+
9+
# checks
1510
assertTrue "Volume size is less than 1024 MiB by default" "[ ${size} -lt 1024 ]"
11+
12+
# cleanup
13+
docker volume rm "${volume}" > /dev/null
1614
}
1715

1816
testCustomVolumeSize() {
19-
size=$(docker run --rm -it -v "${VOLUME_CUSTOM}:/srv" "${IMAGE}" df -m /srv | tail -1 | awk '{print $2}')
17+
local volume size
18+
# setup
19+
volume=$(docker volume create -d "${DRIVER}" -o size=100Mi)
20+
size=$(docker run --rm -it -v "${volume}:/srv" "${IMAGE}" df -m /srv | tail -1 | awk '{print $2}')
21+
22+
# checks
2023
assertTrue "Volume size is less than requested value" "[ ${size} -lt 100 ]"
24+
25+
# cleanup
26+
docker volume rm "${volume}" > /dev/null
2127
}
2228

2329
. test.sh

tests/test_ext4.sh

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,71 @@
22

33
FS="ext4"
44

5-
oneTimeSetUp() {
6-
export VOLUME_SPARSE=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true)
7-
export VOLUME_REGULAR=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false)
5+
testRegularVolumeDoesNotReserveDiskSpace() {
6+
local volume info allocated_size apparent_size
7+
# setup
8+
volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false)
9+
10+
info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}")
11+
allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
12+
apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
13+
14+
# checks
15+
assertTrue "Regular ${FS} volume of ${apparent_size} MiB should take less space: ${allocated_size} MiB" "[ ${allocated_size} -lt ${apparent_size} ]"
16+
17+
# cleanup
18+
docker volume rm "${volume}" > /dev/null
819
}
920

21+
testRegularVolumeChecksDiskSpaceBeforeFormatting() {
22+
local error result count
23+
# setup
24+
25+
## attempt creating 10 GiB volume while we have only 2 GiB of space
26+
error=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false -o size=10GiB 2>&1)
27+
result=$?
28+
29+
## because we shadow real data dir with our test volume we're sure there shouldn't be any volumes
30+
count=$(ls -1 "/var/lib/${DRIVER}/" | wc -l)
1031

11-
oneTimeTearDown() {
12-
docker volume rm "${VOLUME_SPARSE}" > /dev/null
13-
docker volume rm "${VOLUME_REGULAR}" > /dev/null
32+
# checks
33+
assertEquals "1" "${result}"
34+
assertEquals "0" "${count}"
1435
}
1536

16-
testSparseVolumeDoesNotReserveDiskSpace() {
17-
info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${VOLUME_SPARSE}.${FS}")
18-
allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
37+
testSparseVolumeDoesNotCheckAvailableDiskSpace() {
38+
local volume result info apparent_size
39+
# setup
40+
41+
## attempt creating 10 GiB volume while we have only 2 GiB of space
42+
volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true -o size=10GiB)
43+
result=$?
44+
45+
info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}")
1946
apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
2047

21-
assertTrue "Sparse ${FS} volume of ${apparent_size} MiB should take less space: ${allocated_size} MiB" "[ ${allocated_size} -lt ${apparent_size} ]"
48+
# checks
49+
assertEquals "0" "${result}"
50+
assertEquals "10240" "${apparent_size}"
51+
52+
# cleanup
53+
docker volume rm "${volume}" > /dev/null
2254
}
2355

24-
testRegularVolumeDoesNotReserveDiskSpace() {
25-
info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${VOLUME_REGULAR}.${FS}")
56+
testSparseVolumeDoesNotReserveDiskSpace() {
57+
local volume info allocated_size apparent_size
58+
# setup
59+
volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true)
60+
61+
info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}")
2662
allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
2763
apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
2864

29-
assertTrue "Regular ${FS} volume of ${apparent_size} MiB should take less space: ${allocated_size} MiB" "[ ${allocated_size} -lt ${apparent_size} ]"
65+
# checks
66+
assertTrue "Sparse ${FS} volume of ${apparent_size} MiB should take less space: ${allocated_size} MiB" "[ ${allocated_size} -lt ${apparent_size} ]"
67+
68+
# cleanup
69+
docker volume rm "${volume}" > /dev/null
3070
}
3171

3272
. test.sh

tests/test_xfs.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@
22

33
FS="xfs"
44

5-
oneTimeSetUp() {
6-
export VOLUME_SPARSE=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true)
7-
export VOLUME_REGULAR=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false)
8-
}
9-
10-
11-
oneTimeTearDown() {
12-
docker volume rm "${VOLUME_SPARSE}" > /dev/null
13-
docker volume rm "${VOLUME_REGULAR}" > /dev/null
14-
}
15-
165
testSparseVolumeDoesNotTakeDiskSpace() {
17-
info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${VOLUME_SPARSE}.${FS}")
18-
allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
19-
apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
20-
6+
local volume info allocated_size apparent_size
7+
# setup
8+
local volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true)
9+
local info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}")
10+
local allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
11+
local apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
12+
13+
# checks
2114
assertTrue "Sparse ${FS} volume of ${apparent_size} MiB should take less space: ${allocated_size} MiB" "[ ${allocated_size} -lt ${apparent_size} ]"
15+
16+
# cleanup
17+
docker volume rm "${volume}" > /dev/null
2218
}
2319

2420
testRegularVolumeReservesDiskSpace() {
25-
info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${VOLUME_REGULAR}.${FS}")
26-
allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
27-
apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
28-
21+
local volume info allocated_size apparent_size
22+
# setup
23+
local volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false)
24+
local info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}")
25+
local allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
26+
local apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
27+
28+
# checks
2929
assertTrue "Regular ${FS} volume of ${apparent_size} MiB should take at least same space: ${allocated_size} MiB" "[ ${allocated_size} -ge ${apparent_size} ]"
30+
31+
# cleanup
32+
docker volume rm "${volume}" > /dev/null
3033
}
3134

3235
. test.sh

0 commit comments

Comments
 (0)