Skip to content

Commit adfa1a8

Browse files
committed
Tests for dd fallback
1 parent 153a49b commit adfa1a8

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ go mod tidy
2121
```
2222

2323
## Test
24-
on ext4/xfs vs ext3
25-
2624
uid/gid - default & custom
2725

2826
mode - default & custom
2927

3028
inspect - should export status fields
29+
30+
# Extra
31+
if _, err := exec.LookPath("mkfs.xfs"); err != nil {
32+
logrus.Fatal("mkfs.xfs is not available, please install xfsprogs to continue")
33+
}

tests/test.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@ oneTimeSetUp() {
1212

1313
setUp() {
1414
HANDLE=$(mktemp -u)
15-
truncate -s "${1:-2GiB}" "${HANDLE}"
16-
mkfs.xfs "${HANDLE}" &> /dev/null
17-
mount -o nouuid "${HANDLE}" "${DATA_DIR}"
15+
truncate -s "${BASE_SIZE:-2G}" "${HANDLE}"
16+
17+
18+
case "${BASE_FS:-xfs}" in
19+
xfs)
20+
mkfs.xfs "${HANDLE}" &> /dev/null
21+
mount -o nouuid "${HANDLE}" "${DATA_DIR}"
22+
;;
23+
ext*)
24+
mkfs.${BASE_FS} -F "${HANDLE}" &> /dev/null
25+
mount "${HANDLE}" "${DATA_DIR}"
26+
;;
27+
*)
28+
echo "Unsupported BASE fs"
29+
exit 1
30+
;;
31+
esac
1832
}
1933

2034
tearDown() {

tests/test_backing_fs.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
BASE_SIZE="100M"
4+
BASE_FS="ext3"
5+
6+
testFallbackToDdFromFallocateOnUnsupportedFs() {
7+
local error result count
8+
# setup
9+
10+
## for sparse=false we use fallocate and fallback to dd if fallocate is not supported
11+
error=$(docker volume create -d "${DRIVER}" -o fs=xfs -o sparse=false -o size=50MiB 2>&1)
12+
result=$?
13+
14+
## because we shadow real data dir with our test volume we're sure there shouldn't be any volumes
15+
count=$(ls -1 "/var/lib/${DRIVER}/" | grep -v "lost+found" | wc -l)
16+
17+
assertEquals "0" "${result}"
18+
assertEquals "1" "${count}"
19+
}
20+
21+
testDdFailureScenarioWhenThereIsNotEnoughDiskSpace() {
22+
local error result count
23+
# setup
24+
25+
## attempt creating 2 GiB volume while we have only 1 GiB of space
26+
error=$(docker volume create -d "${DRIVER}" -o fs=xfs -o sparse=false -o size=200MiB 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}/" | grep -v "lost+found" | wc -l)
31+
32+
assertEquals "1" "${result}"
33+
assertEquals "0" "${count}"
34+
}
35+
36+
. test.sh

0 commit comments

Comments
 (0)