...
 
Commits (2)
......@@ -4,7 +4,7 @@ load test_helper
load ganggo_helper
@test "$btf create database" {
create_database "g1"
create_database postgres g1
[ "$?" -eq 0 ]
}
......@@ -61,7 +61,7 @@ function send_type() {
# check if ganggo received it
function cmd() {
query "g1" "select count(*) from posts where public = true;"
query postgres g1 "select count(*) from posts where public = true;"
}
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
......@@ -78,7 +78,7 @@ function send_type() {
# check comment
function cmd() {
query "g1" "select count(*) from comments where guid = '$guid';"
query postgres g1 "select count(*) from comments where guid = '$guid';"
}
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
......@@ -94,7 +94,7 @@ function send_type() {
# check comment
function cmd() {
query "g1" "select count(*) from likes where guid = '$guid';"
query postgres g1 "select count(*) from likes where guid = '$guid';"
}
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
......@@ -119,8 +119,8 @@ function send_type() {
}
@test "$btf drop databases" {
drop_database "g1"
drop_database postgres g1
[ "$?" -eq 0 ]
drop_database "d1"
drop_database postgres d1
[ "$?" -eq 0 ]
}
......@@ -7,7 +7,7 @@ load test_helper
load ganggo_helper
@test "$btf create database" {
create_database "g1"
create_database postgres g1
[ "$?" -eq 0 ]
}
......@@ -66,7 +66,7 @@ function send_type() {
function cmd() {
public="true"
[ "$type" == "private" ] && public="false"
query "d1" "select count(*) from posts
query postgres d1 "select count(*) from posts
where guid = '$guid' and public = $public;"
}
code=$(wait_for cmd "1" 120)
......@@ -83,7 +83,7 @@ function send_type() {
[ "$guid" != "null" ]
# check comment
function cmd() {
query "d1" "select count(*) from comments
query postgres d1 "select count(*) from comments
where guid = '$guid';"
}
code=$(wait_for cmd "1" 120)
......@@ -101,7 +101,7 @@ function send_type() {
#[ "$guid" != "null" ]
## check like
#function cmd() {
# query "d1" "select count(*) from likes
# query postgres d1 "select count(*) from likes
# where guid = '$guid';"
#}
#code=$(wait_for cmd "1" 120)
......
......@@ -7,9 +7,9 @@ load test_helper
load ganggo_helper
@test "$btf create databases" {
create_database "g1"
create_database postgres g1
[ "$?" -eq 0 ]
create_database "g2"
create_database postgres g2
[ "$?" -eq 0 ]
}
......@@ -61,7 +61,7 @@ function send_type() {
function cmd() {
public="true"
[ "$type" == "private" ] && public="false"
query "g2" "select count(*) from posts
query postgres g2 "select count(*) from posts
where guid = '$guid' and public = $public;"
}
code=$(wait_for cmd "1" 120)
......@@ -78,7 +78,7 @@ function send_type() {
[ "$guid" != "null" ]
# check comment
function cmd() {
query "g2" "select count(*) from comments
query postgres g2 "select count(*) from comments
where guid = '$guid';"
}
code=$(wait_for cmd "1" 120)
......@@ -96,7 +96,7 @@ function send_type() {
#[ "$guid" != "null" ]
## check like
#function cmd() {
# query "g2" "select count(*) from likes
# query postgres g2 "select count(*) from likes
# where guid = '$guid';"
#}
#code=$(wait_for cmd "1" 120)
......@@ -122,8 +122,8 @@ function send_type() {
}
@test "$btf drop databases" {
drop_database "g1"
drop_database postgres g1
[ "$?" -eq 0 ]
drop_database "g2"
drop_database postgres g2
[ "$?" -eq 0 ]
}
......@@ -8,9 +8,9 @@ load ganggo_helper
load socialhome_helper
@test "$btf create databases" {
create_database "g1"
create_database postgres g1
[ "$?" -eq 0 ]
create_database "s1"
create_database postgres s1
[ "$?" -eq 0 ]
}
......@@ -66,7 +66,7 @@ load socialhome_helper
[ "$uuid" != "null" ]
# check post in ganggo
function cmd() {
query "g1" "select count(*) from posts
query postgres g1 "select count(*) from posts
where guid = '$uuid' and public = true;"
}
code=$(wait_for cmd "1" 120)
......@@ -80,7 +80,7 @@ load socialhome_helper
[ "$?" -eq 0 ]
remove_app $app
[ "$?" -eq 0 ]
drop_database $app
drop_database postgres $app
[ "$?" -eq 0 ]
done
rm -v $curl_params
......
......@@ -20,14 +20,11 @@ function setup() {
# git binary
command -v git
[ "$?" -eq 0 ]
# setup database
docker inspect $(container_id "postgres") > /dev/null || {
init_database;
}
# setup databases
docker inspect $(container_id postgres) > /dev/null || init_postgres;
docker inspect $(container_id mysql) > /dev/null || init_mysql;
# setup redis
docker inspect $(container_id "redis") > /dev/null || {
init_redis;
}
docker inspect $(container_id redis) > /dev/null || init_redis;
}
# fetch "POST" "data1=one&data2=two" "url" "http://server/endpoint"
......@@ -84,8 +81,9 @@ function start_app() {
cid=$(container_id "$1")
echo "Starting docker container $cid (feneas/testsuite_$3) on port $2"
docker run --name=$cid $params \
--link $(container_id "postgres"):postgreshost \
--link $(container_id "redis"):redishost \
--link $(container_id postgres):postgreshost \
--link $(container_id mysql):mysqlhost \
--link $(container_id redis):redishost \
-e DATABASE=$1 -e PORT=$2 -d feneas/testsuite_$3
}
......@@ -167,16 +165,22 @@ function wait_for() {
done
}
# query "g1" "select count(*) from posts;"
# query "postgres" "g1" "select count(*) from posts;"
function query() {
out=$(psql -t -h $(container_ip "postgres") -d $1 -U postgres -c "$2")
if [[ "$1" == "postgres" ]]; then
out=$(psql -t -h $(container_ip "postgres") -d $2 -U postgres -c "$3")
elif [[ "$1" == "mysql" ]]; then
out=$(mysql -h $(container_ip "mysql") -u root -D $2 -Nsr -e "$3")
else
return 1
fi
code=$?
echo -ne $out
return $code
}
# init_database will be triggered on setup()
function init_database() {
# init_postgres will startup a postgres instance
function init_postgres() {
docker run -d --name $(container_id postgres) postgres:latest
cmd="docker logs $(container_id postgres)"
text="ready for start up"
......@@ -184,6 +188,16 @@ function init_database() {
[ "$code" -eq "0" ]
}
# init_mysql will startup a mysql instance
function init_mysql() {
docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 \
--name $(container_id mysql) mysql:5.7
cmd="docker logs $(container_id mysql)"
text="ready for connections"
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
......@@ -193,14 +207,16 @@ function init_redis() {
[ "$code" -eq "0" ]
}
# create_database "g1"
# create_database "postgres" "g1"
function create_database() {
query "postgres" "create database $1;"
db=$1; [[ "$1" == "postgres" ]] && db=postgres
query $1 $db "create database $2;"
}
# drop_database "g1"
# drop_database "postgres" "g1"
function drop_database() {
query "postgres" "drop database $1;"
db=$1; [[ "$1" == "postgres" ]] && db=postgres
query $1 $db "drop database $2;"
}
# json_value "ID"
......
......@@ -6,7 +6,7 @@ load test_helper
@test "$btf create databases" {
for tp in tp1 tp2; do
create_database $tp
create_database postgres $tp
[ "$?" -eq 0 ]
done
}
......@@ -60,7 +60,7 @@ load test_helper
}
@test "$btf check the database on tp1 too" {
cmd='query tp1 "select count(*) from testtable;"'
cmd='query postgres tp1 "select count(*) from testtable;"'
code=$(wait_for "$cmd" "1")
[ "$code" -eq "0" ]
}
......@@ -76,7 +76,7 @@ load test_helper
@test "$btf drop databases" {
for tp in tp1 tp2; do
drop_database $tp
drop_database postgres $tp
[ "$?" -eq 0 ]
done
}