]> git.stg.codes - stg.git/blob - functest/test.sh
62a8a5810946c8ec271eba695b17bfb7b8fe167e
[stg.git] / functest / test.sh
1 #!/bin/sh
2
3 BASEPATH=$1
4
5 if [ "$BASEPATH" == "" ]
6 then
7     printf "Usage: $0 <path>\n"
8     exit -1
9 fi
10
11 if [ ! -d "$BASEPATH" ]
12 then
13     printf "Path '$BASEPATH' does not exist or not a directory.\n"
14     exit -1
15 fi
16
17 STGPATH="$BASEPATH/stg/projects/stargazer"
18
19 cp "stuff/stargazer-files.conf" "$STGPATH/stargazer.conf"
20 cp "stuff/rules" "$STGPATH/"
21 cp "stuff/OnConnect" "$STGPATH/"
22 cp "stuff/OnDisconnect" "$STGPATH/"
23 cp "stuff/OnChange" "$STGPATH/"
24 cp -R "stuff/db-stub" "$STGPATH/db"
25
26 sed -i "s|-STG-PATH-|$STGPATH|g" "$STGPATH/stargazer.conf"
27
28 LOGFILE=`pwd`"/"`date "+%Y-%m-%d-%H%M%S.console.log"`
29
30 cd "$STGPATH"
31
32 "$STGPATH/stargazer" "$STGPATH" >> "$LOGFILE" 2>&1 &
33
34 COUNT=""
35 while true
36 do
37     grep "Stg started successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
38     if [ "$?" == "0" ]
39     then
40         break
41     fi
42     COUNT="$COUNT."
43     if [ "$COUNT" == "....." ]
44     then
45         printf "Failed to start stg in 5 sec.\n"
46         exit -1
47     fi
48     sleep 1
49 done
50
51 PID=`cat "$STGPATH/stargazer.pid"`
52 printf "Started with pid $PID\n"
53
54 SGCONFPATH="$BASEPATH/stg/projects/sgconf"
55
56 RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --get-admins`
57
58 if [ "$?" != "0" ]
59 then
60     printf "Failed to get admins list. Result:\n$RES\n"
61     exit 0
62 fi
63
64 printf "Got admins list:\n$RES\n"
65
66 printf "Stopping...\n"
67 kill $PID
68
69 COUNT=""
70 while true
71 do
72     grep "Stg stopped successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
73     if [ "$?" == "0" ]
74     then
75         break
76     fi
77     COUNT="$COUNT."
78     if [ "$COUNT" == "....." ]
79     then
80         printf "Failed to stop stg in 5 sec.\n"
81         exit -1
82     fi
83     sleep 1
84 done
85
86 printf "Stopped.\n"