Skip to content

Commit e453d9a

Browse files
committed
Add chown tests
1 parent adfa1a8 commit e453d9a

File tree

4 files changed

+143
-9
lines changed

4 files changed

+143
-9
lines changed

driver/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (d Driver) Create(req *v.CreateRequest) error {
113113
}
114114
if uid < 0 {
115115
return errors.Errorf(
116-
"Error creating volume '%s' - 'uid' option should be >= 0 but received '%s'",
116+
"Error creating volume '%s' - 'uid' option should be >= 0 but received '%d'",
117117
req.Name, uid)
118118
}
119119

@@ -133,7 +133,7 @@ func (d Driver) Create(req *v.CreateRequest) error {
133133
}
134134
if gid < 0 {
135135
return errors.Errorf(
136-
"Error creating volume '%s' - 'gid' option should be >= 0 but received '%s'",
136+
"Error creating volume '%s' - 'gid' option should be >= 0 but received '%d'",
137137
req.Name, gid)
138138
}
139139

tests/test_backing_fs.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ BASE_SIZE="100M"
44
BASE_FS="ext3"
55

66
testFallbackToDdFromFallocateOnUnsupportedFs() {
7-
local error result count
7+
local volume result count
88
# setup
99

1010
## 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)
11+
volume=$(docker volume create -d "${DRIVER}" -o fs=xfs -o sparse=false -o size=50MiB 2>&1)
1212
result=$?
1313

1414
## because we shadow real data dir with our test volume we're sure there shouldn't be any volumes
1515
count=$(ls -1 "/var/lib/${DRIVER}/" | grep -v "lost+found" | wc -l)
1616

17-
assertEquals "0" "${result}"
18-
assertEquals "1" "${count}"
17+
assertEquals "Volume creation should succeed" "0" "${result}"
18+
assertEquals "There should be 1 volume" "1" "${count}"
19+
20+
# cleanup
21+
docker volume rm "${volume}" > /dev/null
1922
}
2023

2124
testDdFailureScenarioWhenThereIsNotEnoughDiskSpace() {
@@ -29,8 +32,8 @@ testDdFailureScenarioWhenThereIsNotEnoughDiskSpace() {
2932
## because we shadow real data dir with our test volume we're sure there shouldn't be any volumes
3033
count=$(ls -1 "/var/lib/${DRIVER}/" | grep -v "lost+found" | wc -l)
3134

32-
assertEquals "1" "${result}"
33-
assertEquals "0" "${count}"
35+
assertEquals "Volume creation should fail" "1" "${result}"
36+
assertEquals "There should be no volumes" "0" "${count}"
3437
}
3538

3639
. test.sh

tests/test_chown.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env bash
2+
3+
testDefaultOwner() {
4+
local volume uid gid
5+
# setup
6+
volume=$(docker volume create -d "${DRIVER}")
7+
8+
info=$(docker run --rm -it -v "${volume}:/vol" "${IMAGE}" ls -lan | grep vol)
9+
uid=$(echo "${info}" | awk '{print $3}')
10+
gid=$(echo "${info}" | awk '{print $4}')
11+
12+
# checks
13+
assertEquals "Default user owner is root (uid=0)" "0" "${uid}"
14+
assertEquals "Default group owner is root (gid=0)" "0" "${gid}"
15+
16+
# cleanup
17+
docker volume rm "${volume}" > /dev/null
18+
}
19+
20+
testEmptyValuesIgnored() {
21+
local volume uid gid
22+
# setup
23+
volume=$(docker volume create -d "${DRIVER}" -o uid= -o gid=)
24+
25+
info=$(docker run --rm -it -v "${volume}:/vol" "${IMAGE}" ls -lan | grep vol)
26+
uid=$(echo "${info}" | awk '{print $3}')
27+
gid=$(echo "${info}" | awk '{print $4}')
28+
29+
# checks
30+
assertEquals "User owner should be 0" "0" "${uid}"
31+
assertEquals "Group owner should be 0" "0" "${gid}"
32+
33+
# cleanup
34+
docker volume rm "${volume}" > /dev/null
35+
}
36+
37+
testChangeUser() {
38+
local volume info uid gid
39+
# setup
40+
volume=$(docker volume create -d "${DRIVER}" -o uid=123)
41+
info=$(docker run --rm -it -v "${volume}:/vol" "${IMAGE}" ls -lan | grep vol)
42+
uid=$(echo "${info}" | awk '{print $3}')
43+
gid=$(echo "${info}" | awk '{print $4}')
44+
45+
# checks
46+
assertEquals "User owner should be changed to 123" "123" "${uid}"
47+
assertEquals "Group owner should remain 0" "0" "${gid}"
48+
49+
# cleanup
50+
docker volume rm "${volume}" > /dev/null
51+
}
52+
53+
testChangeGroup() {
54+
local volume info uid gid
55+
# setup
56+
volume=$(docker volume create -d "${DRIVER}" -o gid=456)
57+
info=$(docker run --rm -it -v "${volume}:/vol" "${IMAGE}" ls -lan | grep vol)
58+
uid=$(echo "${info}" | awk '{print $3}')
59+
gid=$(echo "${info}" | awk '{print $4}')
60+
61+
# checks
62+
assertEquals "User owner should remain 0" "0" "${uid}"
63+
assertEquals "Group owner should be changed to 456" "456" "${gid}"
64+
65+
# cleanup
66+
docker volume rm "${volume}" > /dev/null
67+
}
68+
69+
testChangeUserAndGroup() {
70+
local volume info uid gid
71+
# setup
72+
volume=$(docker volume create -d "${DRIVER}" -o uid=123 -o gid=456)
73+
info=$(docker run --rm -it -v "${volume}:/vol" "${IMAGE}" ls -lan | grep vol)
74+
uid=$(echo "${info}" | awk '{print $3}')
75+
gid=$(echo "${info}" | awk '{print $4}')
76+
77+
# checks
78+
assertEquals "User owner should be changed to 123" "123" "${uid}"
79+
assertEquals "Group owner should be changed to 456" "456" "${gid}"
80+
81+
# cleanup
82+
docker volume rm "${volume}" > /dev/null
83+
}
84+
85+
86+
testNegativeUid() {
87+
local volume info error result
88+
# setup
89+
error=$(docker volume create -d "${DRIVER}" -o uid=-1 2>&1)
90+
result=$?
91+
92+
# checks
93+
assertEquals "Volume creation should fail" "1" "${result}"
94+
assertContains "${error}" "'uid' option should be >= 0 but received '-1'"
95+
}
96+
97+
testNonIntegerUid() {
98+
local volume info error result
99+
# setup
100+
error=$(docker volume create -d "${DRIVER}" -o uid=x 2>&1)
101+
result=$?
102+
103+
# checks
104+
assertEquals "Volume creation should fail" "1" "${result}"
105+
assertContains "${error}" "cannot parse 'uid' option value 'x' as an integer: strconv.Atoi: parsing \"x\": invalid syntax"
106+
}
107+
108+
testNegativeGid() {
109+
local volume info error result
110+
# setup
111+
error=$(docker volume create -d "${DRIVER}" -o gid=-1 2>&1)
112+
result=$?
113+
114+
# checks
115+
assertEquals "Volume creation should fail" "1" "${result}"
116+
assertContains "${error}" "'gid' option should be >= 0 but received '-1'"
117+
}
118+
119+
testNonIntegerGid() {
120+
local volume info error result
121+
# setup
122+
error=$(docker volume create -d "${DRIVER}" -o gid=x 2>&1)
123+
result=$?
124+
125+
# checks
126+
assertEquals "Volume creation should fail" "1" "${result}"
127+
assertContains "${error}" "cannot parse 'gid' option value 'x' as an integer: strconv.Atoi: parsing \"x\": invalid syntax"
128+
}
129+
130+
131+
. test.sh

tests/test_disk_space_limits.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ testDefaultVolumeSize() {
1616
testCustomVolumeSize() {
1717
local volume size
1818
# setup
19-
volume=$(docker volume create -d "${DRIVER}" -o size=100Mi)
19+
volume=$(docker volume create -d "${DRIVER}" -o size=100MiB)
2020
size=$(docker run --rm -it -v "${volume}:/srv" "${IMAGE}" df -m /srv | tail -1 | awk '{print $2}')
2121

2222
# checks

0 commit comments

Comments
 (0)