Skip to content

Commit ba8fe32

Browse files
obnoxxxanoopcs9
authored andcommitted
tests: improve the server test script
This change improves the server container test script by adding some informational output and streamlining the error handling a bit Additionallt, it fixes some bad indentation. Update tests/test-samba-container.sh Signed-off-by: Michael Adam <[email protected]> Co-authored-by: Anoop C S <[email protected]>
1 parent 1ef4ab1 commit ba8fe32

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

tests/test-samba-container.sh

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,71 @@
11
#!/bin/bash
22

33

4+
5+
echo "determining container command."
46
if [ -z "${CONTAINER_CMD}" ]; then
5-
CONTAINER_CMD=$(command -v docker || echo "")
7+
CONTAINER_CMD=$(command -v docker || echo )
68
fi
79
if [ -z "${CONTAINER_CMD}" ]; then
8-
CONTAINER_CMD=$(command -v podman || echo "")
10+
CONTAINER_CMD=$(command -v podman || echo )
911
fi
10-
12+
if [ -z "${CONTAINER_CMD}" ]; then
13+
echo "Error determining container command."
14+
exit 1
15+
fi
16+
echo "container command: '${CONTAINER_CMD}'."
17+
echo "creating temporary directory."
1118
TMPDIR="$(mktemp -d)"
1219
rc=$?
1320

1421
if [ $rc -ne 0 ]; then
15-
echo "Error creating temporary directory"
16-
else
17-
CONTAINER_ID="$(${CONTAINER_CMD} run --network=none --name samba \
18-
--volume="${TMPDIR}":/share:Z --rm -d "${LOCAL_TAG}")"
22+
echo "Error creating temporary directory."
23+
exit 1
24+
fi
25+
echo "temporary directory: '${TMPDIR}'"
26+
echo "starting Samba container."
27+
CONTAINER_ID="$(${CONTAINER_CMD} run --network=none --name samba \
28+
--volume="${TMPDIR}":/share:Z --rm -d "${LOCAL_TAG}")"
29+
rc=$?
30+
31+
if [ $rc -ne 0 ]; then
32+
echo "Error running samba container"
33+
exit 1
34+
fi
35+
echo "Container started, ID: '${CONTAINER_ID}'"
36+
37+
# give samba a second to come up
38+
sleep 1
39+
40+
echo "Listing samba shares"
41+
${CONTAINER_CMD} exec "${CONTAINER_ID}" smbclient -U% -L 127.0.0.1
1942
rc=$?
2043

21-
if [ $rc -ne 0 ]; then
22-
echo "Error running samba container"
23-
else
24-
echo "Container started, ID: '${CONTAINER_ID}'"
44+
if [ ${rc} -ne 0 ]; then
45+
echo "Error listing samba shares"
46+
exit 1
47+
fi
2548

26-
# give samba a second to come up
27-
sleep 1
2849

29-
${CONTAINER_CMD} exec "${CONTAINER_ID}" smbclient -U% -L 127.0.0.1
30-
rc=$?
50+
echo "stopping samba container."
3151

32-
if [ $rc -ne 0 ]; then
33-
echo "Error listing samba shares"
34-
fi
35-
fi
52+
${CONTAINER_CMD} kill "${CONTAINER_ID}"
53+
rc=$?
3654

37-
${CONTAINER_CMD} kill "${CONTAINER_ID}"
55+
if [ $rc -ne 0 ]; then
56+
echo "Error stopping samba container"
57+
exit 1
3858
fi
3959

60+
echo "samba container stopped."
61+
62+
63+
64+
65+
echo "removing temporary directory."
4066
rm -rf "${TMPDIR}"
67+
rc=$?
68+
4169

4270
if [ $rc -eq 0 ]; then
4371
echo "Success"

0 commit comments

Comments
 (0)