Commit 20826307 authored by Lukas Matt's avatar Lukas Matt

Merge branch 'fix_count_check' into 'master'

testproject fix count check

See merge request !9
parents 11d70c64 07ed1e15
Pipeline #1285 failed with stage
......@@ -76,9 +76,9 @@ function get() {
function start_app() {
params=""
if [ ! -z ${PRSHA} ]; then
echo "!!!!!!! Custom build active !!!!!!!"
echo "Using repository $PRREPO"
echo "With SHA $PRSHA"
echo "# +++ Custom build active +++" >&3
echo "# Project $PROJECT ($PRREPO)" >&3
echo "# With SHA $PRSHA" >&3
params="-e PROJECT=$PROJECT -e PRSHA=$PRSHA -e PRREPO=$PRREPO"
fi
cid=$(container_id "$1")
......@@ -141,8 +141,9 @@ function wait_for() {
TIMEOUT_PID=$!
while true; do
$1 2>&1 |grep -m 1 "$2" >/dev/null
if [ "$?" -eq 0 ]; then break; fi
res=$(eval $1 2>&1); code=$?
echo "$res" |grep -m 1 "$2" >/dev/null
[ "$?" -eq 0 ] && [ "$code" -eq 0 ] && break
sleep 1
done & >/dev/null 2>&1
CMD_PID=$!
......@@ -176,14 +177,20 @@ function query() {
# init_database will be triggered on setup()
function init_database() {
docker run -d --name $(container_id "postgres") postgres:latest
sleep 5 # timeout for container otherwise docker-logs fails
docker run -d --name $(container_id postgres) postgres:latest
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()
function init_redis() {
docker run -d --name $(container_id "redis") redis:latest
sleep 5 # timeout for container otherwise docker-logs fails
docker run -d --name $(container_id redis) redis:latest
cmd="docker logs $(container_id redis)"
text="Ready to accept connections"
code=$(wait_for "$cmd" "$text")
[ "$code" -eq "0" ]
}
# create_database "g1"
......
......@@ -32,7 +32,7 @@ load test_helper
@test "$btf start testproject#2 server" {
start_app tp2 3000 testproject$(latest_tag testproject)
[ "$?" -eq 0 ]
cmd="docker logs $(container_id tp1)"
cmd="docker logs $(container_id tp2)"
text="CREATE TABLE"
code=$(wait_for "$cmd" "$text")
[ "$code" -eq "0" ]
......@@ -54,17 +54,15 @@ load test_helper
}
@test "$btf test count on tp1, it should be one" {
get "http://$(container_ip tp1):3000"
echo "expected 200, got $HTTP_STATUS_CODE"
[ "$HTTP_STATUS_CODE" == "200" ]
echo "expected 1, got $HTTP_BODY"
[ "$HTTP_BODY" == "1" ]
cmd='get "http://'$(container_ip tp1)':3000"'
code=$(wait_for "$cmd" "1")
[ "$code" -eq "0" ]
}
@test "$btf check the database on tp1 too" {
result=$(query tp1 "select count(*) from testtable;")
echo "expected 1, got $result"
[[ $result =~ "1" ]]
cmd='query tp1 "select count(*) from testtable;"'
code=$(wait_for "$cmd" "1")
[ "$code" -eq "0" ]
}
@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