-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·122 lines (107 loc) · 3.7 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·122 lines (107 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
# automated smoke test for the rsync container
# builds the image, starts the rsync daemon and asserts rsync actually works:
# - reports the expected version
# - performs a local file round-trip (rsync + diff)
# - performs a round-trip *through the running rsync daemon*
set -eu
IMAGE=rsync-test
NAME=rsync-test-run
EXPECTED_VERSION=3.4.1
FAILED=0
fail() {
echo "FAIL: $*" >&2
FAILED=1
}
cleanup() {
echo ">> cleanup: removing container $NAME"
docker rm -f "$NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT INT TERM
echo ">> building image $IMAGE"
docker build -t "$IMAGE" .
echo ">> (re)starting container $NAME"
docker rm -f "$NAME" >/dev/null 2>&1 || true
# expose a writable, unauthenticated module so we can transfer *through* the
# daemon. RSYNC_VOLUME_CONFIG_* is appended to rsyncd.conf by the entrypoint
# (';' becomes a newline).
docker run -d --name "$NAME" \
-e RSYNC_VOLUME_CONFIG_test='[testmod]; path = /shares/test; comment = testsuite; read only = no; list = yes; use chroot = no; uid = root; gid = root' \
"$IMAGE"
echo ">> waiting for the rsync daemon to come up (up to ~30s)"
READY=0
i=0
while [ "$i" -lt 15 ]; do
if ! docker ps --format '{{.Names}}' | grep -q "^${NAME}$"; then
echo "!! container is not running anymore, dumping logs:" >&2
docker logs "$NAME" >&2 2>&1 || true
fail "container exited during startup"
break
fi
if docker exec "$NAME" ps aux 2>/dev/null | grep -q '[r]sync .*--daemon'; then
READY=1
break
fi
i=$((i + 1))
sleep 2
done
if [ "$READY" -ne 1 ] && [ "$FAILED" -eq 0 ]; then
echo "!! rsync daemon did not come up in time, dumping logs:" >&2
docker logs "$NAME" >&2 2>&1 || true
fail "timed out waiting for rsync daemon"
fi
# only run the deeper assertions if the container is still up
if docker ps --format '{{.Names}}' | grep -q "^${NAME}$"; then
echo ">> assert: container is running"
docker ps --format '{{.Names}}' | grep -q "^${NAME}$" \
&& echo "ok - container running" || fail "container not running"
echo ">> assert: rsync --version reports $EXPECTED_VERSION"
VERSION_LINE=$(docker exec "$NAME" rsync --version 2>/dev/null | head -n1)
if echo "$VERSION_LINE" | grep -q "version $EXPECTED_VERSION"; then
echo "ok - $VERSION_LINE"
else
fail "unexpected rsync version (got: '$VERSION_LINE')"
fi
echo ">> assert: rsync daemon process present"
if docker exec "$NAME" ps aux | grep -q '[r]sync .*--daemon'; then
echo "ok - rsync daemon running"
else
fail "rsync --daemon process not found"
fi
echo ">> assert: local file round-trip (rsync + cmp)"
if docker exec "$NAME" sh -c '
set -e
mkdir -p /tmp/src /tmp/dst
head -c 65536 /dev/urandom > /tmp/src/payload.bin
rsync -a /tmp/src/payload.bin /tmp/dst/payload.bin
cmp /tmp/src/payload.bin /tmp/dst/payload.bin
'; then
echo "ok - local round-trip transferred an identical copy"
else
fail "local rsync round-trip failed"
fi
echo ">> assert: round-trip through the rsync daemon (rsync://)"
if docker exec "$NAME" sh -c '
set -e
mkdir -p /shares/test
head -c 131072 /dev/urandom > /tmp/daemon-src.bin
# push into the daemon module, then pull it back out
rsync -a /tmp/daemon-src.bin rsync://localhost/testmod/daemon-src.bin
rsync -a rsync://localhost/testmod/daemon-src.bin /tmp/daemon-back.bin
cmp /tmp/daemon-src.bin /tmp/daemon-back.bin
'; then
echo "ok - daemon round-trip transferred an identical copy"
else
echo "!! dumping container logs:" >&2
docker logs "$NAME" >&2 2>&1 || true
fail "rsync daemon round-trip failed"
fi
fi
echo
if [ "$FAILED" -eq 0 ]; then
echo "ALL TESTS PASSED"
exit 0
else
echo "SOME TESTS FAILED"
exit 1
fi