Skip to content

Commit 00d9ed7

Browse files
committed
Trap and clean up
1 parent 48da00d commit 00d9ed7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tests.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,24 @@ wait_for_ready() {
3434

3535
wait_for_removed() {
3636
for i in {1..30}; do
37-
if ! docker ps -q --filter "name=http-echo-tests" | grep -q .; then
37+
if ! docker ps -aq --filter "name=http-echo-tests" | grep -q .; then
3838
return 0
3939
fi
4040
sleep 0.5
4141
done
4242
echo "Container failed to stop"; exit 1
4343
}
4444

45+
cleanup() {
46+
echo "Cleaning up..."
47+
docker stop http-echo-tests 2>/dev/null || true
48+
docker rm http-echo-tests 2>/dev/null || true
49+
popd 2>/dev/null || true
50+
rm -rf testarea
51+
}
52+
53+
trap cleanup EXIT
54+
4555
if ! [ -x "$(command -v jq)" ]; then
4656
message "JQ not installed. Installing..."
4757
sudo apt -y install jq
@@ -747,6 +757,4 @@ message " Stop containers "
747757
docker stop http-echo-tests
748758
wait_for_removed
749759

750-
popd
751-
rm -rf testarea
752760
message "DONE"

0 commit comments

Comments
 (0)