Commit 07ed1e15 authored by zauberstuhl's avatar zauberstuhl

testproject fix count check

parent 11d70c64
...@@ -76,9 +76,9 @@ function get() { ...@@ -76,9 +76,9 @@ function get() {
function start_app() { function start_app() {
params="" params=""
if [ ! -z ${PRSHA} ]; then if [ ! -z ${PRSHA} ]; then
echo "!!!!!!! Custom build active !!!!!!!" echo "# +++ Custom build active +++" >&3
echo "Using repository $PRREPO" echo "# Project $PROJECT ($PRREPO)" >&3
echo "With SHA $PRSHA" echo "# With SHA $PRSHA" >&3
params="-e PROJECT=$PROJECT -e PRSHA=$PRSHA -e PRREPO=$PRREPO" params="-e PROJECT=$PROJECT -e PRSHA=$PRSHA -e PRREPO=$PRREPO"
fi fi
cid=$(container_id "$1") cid=$(container_id "$1")
...@@ -141,8 +141,9 @@ function wait_for() { ...@@ -141,8 +141,9 @@ function wait_for() {
TIMEOUT_PID=$! TIMEOUT_PID=$!
while true; do while true; do
$1 2>&1 |grep -m 1 "$2" >/dev/null res=$(eval $1 2>&1); code=$?
if [ "$?" -eq 0 ]; then break; fi echo "$res" |grep -m 1 "$2" >/dev/null
[ "$?" -eq 0 ] && [ "$code" -eq 0 ] && break
sleep 1 sleep 1
done & >/dev/null 2>&1 done & >/dev/null 2>&1
CMD_PID=$! CMD_PID=$!
...@@ -176,14 +177,20 @@ function query() { ...@@ -176,14 +177,20 @@ function query() {
# init_database will be triggered on setup() # init_database will be triggered on setup()
function init_database() { function init_database() {
docker run -d --name $(container_id "postgres") postgres:latest docker run -d --name $(container_id postgres) postgres:latest
sleep 5 # timeout for container otherwise docker-logs fails cmd="docker logs $(container_id postgres)"
text="ready for start up"
code=$(wait_for "$cmd" "$text")
[ "$code" -eq "0" ]
} }
# init_redis will be triggered on setup() # init_redis will be triggered on setup()
function init_redis() { function init_redis() {
docker run -d --name $(container_id "redis") redis:latest docker run -d --name $(container_id redis) redis:latest
sleep 5 # timeout for container otherwise docker-logs fails cmd="docker logs $(container_id redis)"
text="Ready to accept connections"
code=$(wait_for "$cmd" "$text")
[ "$code" -eq "0" ]
} }
# create_database "g1" # create_database "g1"
......
...@@ -32,7 +32,7 @@ load test_helper ...@@ -32,7 +32,7 @@ load test_helper
@test "$btf start testproject#2 server" { @test "$btf start testproject#2 server" {
start_app tp2 3000 testproject$(latest_tag testproject) start_app tp2 3000 testproject$(latest_tag testproject)
[ "$?" -eq 0 ] [ "$?" -eq 0 ]
cmd="docker logs $(container_id tp1)" cmd="docker logs $(container_id tp2)"
text="CREATE TABLE" text="CREATE TABLE"
code=$(wait_for "$cmd" "$text") code=$(wait_for "$cmd" "$text")
[ "$code" -eq "0" ] [ "$code" -eq "0" ]
...@@ -54,17 +54,15 @@ load test_helper ...@@ -54,17 +54,15 @@ load test_helper
} }
@test "$btf test count on tp1, it should be one" { @test "$btf test count on tp1, it should be one" {
get "http://$(container_ip tp1):3000" cmd='get "http://'$(container_ip tp1)':3000"'
echo "expected 200, got $HTTP_STATUS_CODE" code=$(wait_for "$cmd" "1")
[ "$HTTP_STATUS_CODE" == "200" ] [ "$code" -eq "0" ]
echo "expected 1, got $HTTP_BODY"
[ "$HTTP_BODY" == "1" ]
} }
@test "$btf check the database on tp1 too" { @test "$btf check the database on tp1 too" {
result=$(query tp1 "select count(*) from testtable;") cmd='query tp1 "select count(*) from testtable;"'
echo "expected 1, got $result" code=$(wait_for "$cmd" "1")
[[ $result =~ "1" ]] [ "$code" -eq "0" ]
} }
@test "$btf stop and delete the containers" { @test "$btf stop and delete the containers" {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment