Просмотр исходного кода

test/unit: fix bashism - use `.` instead of `source` and use regular syntax files

Mikko Lehto 8 лет назад
Родитель
Сommit
915efd3bfc

+ 1 - 1
test/unit/1.sh

@@ -19,7 +19,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
+. include/common
 
 CFG=1.cfg
 

+ 1 - 1
test/unit/10.sh

@@ -19,7 +19,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
+. include/common
 
 cd $CTL_DIR
 

+ 3 - 3
test/unit/11.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 CFG=11.cfg
 

+ 2 - 2
test/unit/12.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 CFG=12.cfg
 TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`

+ 3 - 3
test/unit/13.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 CFG=13.cfg
 

+ 2 - 2
test/unit/14.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 CFG=14.cfg
 

+ 2 - 2
test/unit/15.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 CFG=15.cfg
 

+ 2 - 2
test/unit/16.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 # Needs a default kamailio database setup for postgres
 

+ 2 - 2
test/unit/17.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 if ! (check_kamailio && check_module "db_berkeley" ); then
 	exit 0

+ 2 - 2
test/unit/18.sh

@@ -20,8 +20,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 if ! (check_kamailio); then
 	exit 0

+ 3 - 3
test/unit/19.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
 	exit 0

+ 3 - 3
test/unit/2.sh

@@ -21,9 +21,9 @@
 
 # Needs a default kamailio database setup for mysql
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 CFG=2.cfg
 

+ 3 - 3
test/unit/20.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
 	exit 0

+ 3 - 3
test/unit/21.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
 	exit 0

+ 3 - 3
test/unit/22.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipsak && check_kamailio && check_module "db_postgres" && check_postgres); then
 	exit 0

+ 3 - 3
test/unit/23.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_kamailio && check_module "carrierroute" && check_module "db_postgres" && check_postgres); then
 	exit 0

+ 2 - 2
test/unit/24.sh

@@ -22,7 +22,7 @@
 # Needs a mysql database, the root user password must be given
 # in the file 'dbrootpw' in the test directory
 
-source include/common
+. include/common
 
 if [ ! -f ~/.pgpass ] ; then
        echo "no .pgpass file, not run"
@@ -55,4 +55,4 @@ mv $CTLRC.bak $CTLRC
 mv $DBCTL.bak $DBCTL
 
 cd -
-exit $ret
+exit $ret

+ 3 - 3
test/unit/25.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 function cleanup() {
 	killall -9 sipp > /dev/null 2>&1

+ 3 - 3
test/unit/26.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then
 	exit 0

+ 3 - 3
test/unit/27.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_mysql" \
 	&& check_module "presence" && check_module "presence_xml" \

+ 3 - 3
test/unit/28.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_module "cpl-c" && check_mysql); then
 	exit 0

+ 2 - 2
test/unit/29.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_postgres" && check_module "cpl-c"); then
 	exit 0

+ 2 - 2
test/unit/3.sh

@@ -25,14 +25,14 @@
 # If MySQL root password is empty, add in the file the line:
 # PWSKIP=yes
 
-source include/common
+. include/common
 
 if [ ! -f dbrootpw ] ; then
 	echo "no root password, not run"
 	exit 0
 fi ;
 
-source dbrootpw
+. dbrootpw
 
 tmp_name=""$RANDOM"_kamailiodb_tmp"
 

+ 2 - 2
test/unit/30.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 if ! (check_sipp && check_kamailio && check_module "carrierroute"); then
 	exit 0

+ 3 - 3
test/unit/31.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_kamailio && check_module "db_mysql" && check_mysql); then
 	exit 0

+ 2 - 2
test/unit/4.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 CFG=4.cfg
 

+ 3 - 3
test/unit/42.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then
 	exit 0

+ 3 - 3
test/unit/43.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_kamailio && check_module "utils" && check_module "db_mysql" && check_mysql); then
 	exit 0

+ 3 - 3
test/unit/44.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipsak && check_kamailio && check_module "db_unixodbc" && check_unixodbc); then
 	exit 0

+ 3 - 3
test/unit/45.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql && check_module "memcached"); then
 	exit 0

+ 3 - 3
test/unit/46.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql ); then
 	exit 0

+ 2 - 2
test/unit/5.sh

@@ -21,8 +21,8 @@
 
 # Needs a default kamailio database setup for mysql
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 CFG=$TOP_DIR/etc/kamailio.cfg
 

+ 3 - 3
test/unit/50.sh

@@ -19,9 +19,9 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
-source include/database
+. include/common
+. include/require.sh
+. include/database.sh
 
 CFG=50.cfg
 

+ 2 - 2
test/unit/6.sh

@@ -19,8 +19,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 CFG=2.cfg
 

+ 2 - 2
test/unit/7.sh

@@ -23,8 +23,8 @@
 
 # Needs a default kamailio database setup for mysql
 
-source include/common
-source include/require
+. include/common
+. include/require.sh
 
 CFG=7.cfg
 

+ 1 - 1
test/unit/8.sh

@@ -19,7 +19,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
+. include/common
 
 tmp_name=""$RANDOM"_kamailiodb_tmp"
 

+ 1 - 1
test/unit/9.sh

@@ -19,7 +19,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-source include/common
+. include/common
 
 cd $CTL_DIR
 

+ 4 - 0
test/unit/include/common

@@ -25,3 +25,7 @@ KILL="killall -15 $BNAME"
 PIDFILE="${RUN_DIR}/kamailio.pid"
 # test directory relative to root
 TEST_DIR="test/unit"
+
+kill_kamailio() {
+	kill $(cat ${PIDFILE})
+}

+ 72 - 0
test/unit/include/database.sh

@@ -0,0 +1,72 @@
+# Copyright (C) 2017 [email protected]
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of kamailio, a free SIP server.
+#
+# kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+. include/common
+KAMUSER="kamailio"
+MYSQL="mysql kamailio --show-warnings --batch --user="${KAMUSER}" --password=kamailiorw -e"
+
+export PGPASSWORD="kamailiorw"
+PSQL="psql -A -t -n -q -h localhost -U kamailio kamailio -c"
+
+ISQL="isql -b -v -d0x0 kamailio kamailio kamailiorw"
+
+check_mysql() {
+	$MYSQL "select * from location;" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return 1
+	fi;
+	$MYSQL "insert into location (user_agent) values ('___test___');" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return 1
+	fi;
+	$MYSQL "delete from location where user_agent ='___test___';" > /dev/null
+	return 0
+}
+
+check_postgres() {
+	$PSQL "select * from location;" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return 1
+	fi;
+	$PSQL "insert into location (user_agent) values ('___test___');" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return 1
+	fi;
+	$PSQL "delete from location where user_agent ='___test___';" > /dev/null
+	return 0
+}
+
+check_unixodbc() {
+	echo "select * from location;" | $ISQL  > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return 1
+	fi;
+	echo "insert into location (id, user_agent) values ('$RANDOM', '___test___');" | $ISQL > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return 1
+	fi;
+	echo "delete from location where user_agent ='___test___';" | $ISQL > /dev/null
+	return 0
+}

+ 1 - 4
test/unit/include/require.sh

@@ -1,5 +1,5 @@
+# Copyright (C) 2017 Mikko Lehto
 # Copyright (C) 2008 1&1 Internet AG
-# Copyright (C) 2016 Mikko Lehto
 #
 # This file is part of kamailio, a free SIP server.
 #
@@ -64,6 +64,3 @@ check_sipsak() {
 	return 0
 }
 
-kill_kamailio() {
-	kill $(cat ${PIDFILE})
-}