Skip to content

Instantly share code, notes, and snippets.

@spikeekips
Created September 14, 2021 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spikeekips/f5d9a6bbf57c8b6f776b3615ad0002ec to your computer and use it in GitHub Desktop.
Save spikeekips/f5d9a6bbf57c8b6f776b3615ad0002ec to your computer and use it in GitHub Desktop.
#!/bin/bash
#set -x
finish() {
tput sgr0
docker volume prune -f
docker container prune -f
}
trap finish EXIT
line() {
s=$(echo "$1" | tr ' ' '|')
l=$(expr 77 - ${#s})
printf " |%s|%${l}s\n" $s | tr ' ' '-' | tr '|' ' '
}
s=""
found=1
if [ ! -z "$1" ];then
s="$1"
found=0
fi
only=0
if [ $found -eq 0 ];then
echo $s | grep '\$$' >/dev/null
if [ $? -eq 0 ];then
only=1
s=$(echo $s | sed -e 's/\$$//g')
fi
fi
ss=""
ffound=1
if [ ! -z "$2" ];then
ss="$2"
ffound=0
fi
l=$(go list -tags 'test mongodb' -json ./... | jq -r -c '. | .Dir' | sed -e "s@$(pwd)/@@g")
gs=$(date +%s)
rm -rf /tmp/localfs-* || true
docker volume prune -f || true
docker container prune -f
(docker rm -f mitum-test-mongo-27017; docker run --name mitum-test-mongo-27017 -it -p 27017:27017 -d mongo) || true
sleep 2
go clean -testcache
for i in $l
do
if [ "$i" == "$s" ];then
found=1
elif [ $found -ne 1 ];then
continue
fi
failed=0
ts=$(find $i -maxdepth 1 -name '*.go' -exec grep 'func Test.*' {} \; | sed -e 's/.*func //g' -e 's/(.*//g' | sort)
for t in $ts
do
echo $t | grep "$ss" >/dev/null
if [ $? -eq 0 ];then
ffound=1
fi
if [ $ffound -ne 1 ];then
continue
fi
igs=$(date +%s)
line $i
time go test -race -tags 'test mongodb' -v -timeout 10m -failfast ./$i -run "^$t$"
e=$?
d=$(expr $(date +%s) - $igs)
echo
echo 'elapsed time: ' $(date -d@$d -u +%H:%M:%S)
echo '--------------------------------------------------------------------------------'
if [ $e -ne 0 ];then
failed=1
break
fi
echo '> in /tmp'
tput setaf 1
ls -al /tmp | grep -v 'go.*\|\.log\|\..*\|.*vim.*\|tmux-\|ssh\|vmware\|^total '
tput sgr0
echo
echo '> in mongo'
mongo --quiet -eval 'db.adminCommand( { listDatabases: 1 } )' | sed -e 's/NumberLong(\([0-9][0-9]*\))/\1/g' | jq '.databases | .[] | select((.name == "admin" or .name == "config" or .name == "local") | not)'
echo
done
if [ $failed -eq 1 ];then
exit 1
break
fi
if [ $only -eq 1 ];then
break
fi
done 2>&1 | tee --output-error=exit /tmp/a.log
exitcode=${PIPESTATUS[0]}
if [ $exitcode -eq 0 ];then
tput setaf 2
else
tput setaf 1
fi
d=$(expr $(date +%s) - $gs)
echo
echo 'total elapsed time: ' $(date -d@$d -u +%H:%M:%S)
echo exit $exitcode
echo
exit $exitcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment