test/unit: fix bashism - use `.` instead of `source` and use regular syntax files
authorMikko Lehto <mslehto@iki.fi>
Wed, 4 Jan 2017 18:55:32 +0000 (20:55 +0200)
committerMikko Lehto <mslehto@iki.fi>
Thu, 5 Jan 2017 00:50:21 +0000 (02:50 +0200)
40 files changed:
test/unit/1.sh
test/unit/10.sh
test/unit/11.sh
test/unit/12.sh
test/unit/13.sh
test/unit/14.sh
test/unit/15.sh
test/unit/16.sh
test/unit/17.sh
test/unit/18.sh
test/unit/19.sh
test/unit/2.sh
test/unit/20.sh
test/unit/21.sh
test/unit/22.sh
test/unit/23.sh
test/unit/24.sh
test/unit/25.sh
test/unit/26.sh
test/unit/27.sh
test/unit/28.sh
test/unit/29.sh
test/unit/3.sh
test/unit/30.sh
test/unit/31.sh
test/unit/4.sh
test/unit/42.sh
test/unit/43.sh
test/unit/44.sh
test/unit/45.sh
test/unit/46.sh
test/unit/5.sh
test/unit/50.sh
test/unit/6.sh
test/unit/7.sh
test/unit/8.sh
test/unit/9.sh
test/unit/include/common
test/unit/include/database.sh [new file with mode: 0644]
test/unit/include/require.sh

index 4ec2811..50a1c90 100755 (executable)
@@ -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
 
index 47bbc9d..fe50552 100755 (executable)
@@ -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
 
index 4bbb9ad..133b68c 100755 (executable)
@@ -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
 
index 19c16f7..918744e 100755 (executable)
@@ -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`
index a47963b..bbfec25 100755 (executable)
@@ -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
 
index 4114f85..eb9fab2 100755 (executable)
@@ -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
 
index 5cceb05..f5f7033 100755 (executable)
@@ -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
 
index ddcd615..7011314 100755 (executable)
@@ -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
 
index 2bf6154..318c18d 100755 (executable)
@@ -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
index 5f618e7..4afaa2f 100755 (executable)
@@ -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
index 1042bc6..9114367 100755 (executable)
@@ -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
index b012296..b803c5d 100755 (executable)
@@ -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
 
index 3689c7d..17372bb 100755 (executable)
@@ -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
index b0fe80c..0eafdd8 100755 (executable)
@@ -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
index 0849225..3466321 100755 (executable)
@@ -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
index 375cfe7..3a03719 100755 (executable)
@@ -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
index 325c3df..196bb9d 100755 (executable)
@@ -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
\ No newline at end of file
+exit $ret
index 974f42e..36841ca 100755 (executable)
@@ -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
index 589805b..7308139 100755 (executable)
@@ -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
index ec3feae..97a8ce5 100755 (executable)
@@ -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" \
index a9969ed..23d08ed 100755 (executable)
@@ -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
index f75159b..b12ebfa 100755 (executable)
@@ -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
index 9578c01..03c98b0 100755 (executable)
 # 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"
 
index 084858e..a88519c 100755 (executable)
@@ -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
index 258fefc..cc15e7a 100755 (executable)
@@ -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
index fb2dfff..f75349a 100755 (executable)
@@ -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
 
index 8415649..5b0faa0 100755 (executable)
@@ -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
index dcb8a7d..a77f7cf 100755 (executable)
@@ -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
index c585be2..8ab0fdc 100755 (executable)
@@ -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
index b01b9aa..db05ad8 100755 (executable)
@@ -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
index 1ad64fe..a2e1ea5 100755 (executable)
@@ -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
index d4fe178..d7d1c62 100755 (executable)
@@ -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
 
index ec78074..14571c3 100755 (executable)
@@ -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
 
index 6ddd968..b6ed5a3 100755 (executable)
@@ -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
 
index 05ba291..33f419f 100755 (executable)
@@ -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
 
index 3165e2f..7d41c53 100755 (executable)
@@ -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"
 
index 8e21626..c34c9b2 100755 (executable)
@@ -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
 
index 86ee0dc..1868ef7 100644 (file)
@@ -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})
+}
diff --git a/test/unit/include/database.sh b/test/unit/include/database.sh
new file mode 100644 (file)
index 0000000..c78c62b
--- /dev/null
@@ -0,0 +1,72 @@
+# Copyright (C) 2017 mslehto@iki.fi
+# 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
+}
index c7642bb..07d800c 100644 (file)
@@ -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})
-}