Browse Source

whole tests batch

nas 3 years ago
parent
commit
23870c262c
11 changed files with 106 additions and 78 deletions
  1. 0
    2
      test/config.sh
  2. 15
    15
      test/del_line.sh
  3. 15
    15
      test/get_line.sh
  4. 13
    11
      test/get_table.sh
  5. 4
    2
      test/login.sh
  6. 15
    15
      test/post_line.sh
  7. 19
    18
      test/set_line.sh
  8. 6
    0
      test/test.conf
  9. 4
    0
      test/tests.sh
  10. 12
    0
      test/tools/show_result.sh
  11. 3
    0
      test/tools/title.sh

+ 0
- 2
test/config.sh View File

@@ -6,10 +6,8 @@ dir_path=$(dirname $script_path)
6 6
 get_conf(){
7 7
     while IFS= read -r line ;
8 8
     do
9
-	echo "$line"
10 9
 	cf_key=`echo $line | awk 'BEGIN {FS = "="} {print $1}'`
11 10
 	cf_val=`echo $line | awk 'BEGIN {FS = "="} {print $2}'`
12
-	echo "$cf_key $cf_val"
13 11
 	eval $cf_key=$cf_val
14 12
     done < $1
15 13
 }

+ 15
- 15
test/del_line.sh View File

@@ -3,29 +3,29 @@
3 3
 help() {
4 4
     echo "Syntaxe"
5 5
     echo "‾‾‾‾‾‾‾"
6
-    echo "sh $0 [ adresse ] [ table ] [ id ]\n"
6
+    echo "sh $0 [ adresse ] [ tablename ] [ id ]\n"
7 7
 }
8 8
 
9
-if [ -z "$1" ]
9
+if [ "$1" ]
10 10
 then
11
-    echo "Missing parameters : web adresses is needed\n"
12
-    help
13
-    exit
11
+    address=$1
14 12
 fi
15
-if [ -z "$2" ]
13
+if [ "$2" ]
16 14
 then
17
-    echo "Missing parameters : tablename is needed\n"
18
-    help
19
-    exit
15
+    tablename=$2
20 16
 fi
21
-if [ -z "$3" ]
17
+if [ "$3" ]
22 18
 then
23
-    echo "Missing parameters : an id is needed\n"
24
-    help
25
-    exit
19
+    id=$3
26 20
 fi
27 21
 
22
+. ./config.sh
23
+. ./dep/address.sh
24
+. ./dep/tablename.sh
25
+. ./dep/id.sh
26
+
27
+. ./tools/title.sh
28 28
 echo "Delete id $3 of table $2"
29
-echo "$1 $2 $3"
30
-curl --header "Content-Type: application/json" -X "DELETE" -b cookie.txt $1/api.php/records/$2/$3
29
+result=`curl --header "Content-Type: application/json" -X "DELETE" -b cookie.txt $address/api.php/records/$tablename/$id 2> /dev/null`
30
+sh tools/show_result.sh $result
31 31
 echo "\n"

+ 15
- 15
test/get_line.sh View File

@@ -6,26 +6,26 @@ help() {
6 6
     echo "sh $0 [ adresse ] [ tablename ] [ id ]\n"
7 7
 }
8 8
 
9
-if [ -z "$1" ]
9
+if [ "$1" ]
10 10
 then
11
-    echo "Missing parameters : web adresses is needed\n"
12
-    help
13
-    exit
11
+    address=$1
14 12
 fi
15
-if [ -z "$2" ]
13
+if [ "$2" ]
16 14
 then
17
-    echo "Missing parameters : tablename is needed\n"
18
-    help
19
-    exit
15
+    tablename=$2
20 16
 fi
21
-if [ -z "$3" ]
17
+if [ "$3" ]
22 18
 then
23
-    echo "Missing parameters : an id is needed\n"
24
-    help
25
-    exit
19
+    id=$3
26 20
 fi
27 21
 
28
-echo "Get id $3 of table $2"
29
-echo "$1 $2 $3"
30
-curl --header "Content-Type: application/json" -b cookie.txt $1/api.php/records/$2/$3
22
+. ./config.sh
23
+. ./dep/address.sh
24
+. ./dep/tablename.sh
25
+. ./dep/id.sh
26
+
27
+. ./tools/title.sh
28
+echo "Get id $id of table $tablename"
29
+result=`curl --header "Content-Type: application/json" -b cookie.txt $address/api.php/records/$tablename/$id 2> /dev/null`
30
+sh tools/show_result.sh $result
31 31
 echo "\n"

+ 13
- 11
test/get_table.sh View File

@@ -6,19 +6,21 @@ help() {
6 6
     echo "sh $0 [ adresse ] [ tablename ]\n"
7 7
 }
8 8
 
9
-if [ -z "$1" ]
9
+if [ "$1" ]
10 10
 then
11
-    echo "Missing parameters : web adresses is needed\n"
12
-    help
13
-    exit
11
+    address=$1
14 12
 fi
15
-if [ -z "$2" ]
13
+if [ "$2" ]
16 14
 then
17
-    echo "Missing parameters : tablename is needed\n"
18
-    help
19
-    exit
15
+    tablename=$2
20 16
 fi
21
-echo "List entries from table $2"
22
-echo "$1 $2 $3"
23
-curl --header "Content-Type: application/json" -b cookie.txt $1/api.php/records/$2
17
+
18
+. ./config.sh
19
+. ./dep/address.sh
20
+. ./dep/tablename.sh
21
+
22
+. ./tools/title.sh
23
+echo "List entries from table $tablename"
24
+result=`curl --header "Content-Type: application/json" -b cookie.txt $address/api.php/records/$tablename 2>/dev/null`
25
+sh tools/show_result.sh $result
24 26
 echo "\n"

+ 4
- 2
test/login.sh View File

@@ -24,6 +24,8 @@ fi
24 24
 . ./dep/username.sh
25 25
 . ./dep/password.sh
26 26
 
27
-echo "Login as $2 in cookie.txt"
28
-curl --header "Content-Type: application/json" --cookie-jar cookie.txt --request POST --data "{\"username\":\"$username\",\"password\":\"$password\"}" $address/api.php/login
27
+. ./tools/title.sh
28
+echo "Login as $username in cookie.txt"
29
+result=`curl --header "Content-Type: application/json" --cookie-jar cookie.txt --request POST --data "{\"username\":\"$username\",\"password\":\"$password\"}" $address/api.php/login 2>/dev/null`
30
+sh tools/show_result.sh $result
29 31
 echo "\n"

+ 15
- 15
test/post_line.sh View File

@@ -6,26 +6,26 @@ help() {
6 6
     echo "sh $0 [ adresse ] [ tablename ] [ data ]\n"
7 7
 }
8 8
 
9
-if [ -z "$1" ]
9
+if [ "$1" ]
10 10
 then
11
-    echo "Missing parameters : web adresses is needed\n"
12
-    help
13
-    exit
11
+    address=$1
14 12
 fi
15
-if [ -z "$2" ]
13
+if [ "$2" ]
16 14
 then
17
-    echo "Missing parameters : tablename is needed\n"
18
-    help
19
-    exit
15
+    tablename=$2
20 16
 fi
21
-if [ -z "$3" ]
17
+if [ "$3" ]
22 18
 then
23
-    echo "Missing parameters : data are needed\n"
24
-    help
25
-    exit
19
+    data=$3
26 20
 fi
27 21
 
28
-echo "Post $3 to table $2"
29
-echo "$1 $2 $3"
30
-curl --header "Content-Type: application/json" -b cookie.txt --data "$3" $1/api.php/records/$2/
22
+. ./config.sh
23
+. ./dep/address.sh
24
+. ./dep/tablename.sh
25
+. ./dep/data.sh
26
+
27
+. ./tools/title.sh
28
+echo "Post $data to table $tablename"
29
+result=`curl --header "Content-Type: application/json" -b cookie.txt -X POST --data ’$data’ $address/api.php/records/$tablename/ 2>/dev/null`
30
+sh tools/show_result.sh $result
31 31
 echo "\n"

+ 19
- 18
test/set_line.sh View File

@@ -6,32 +6,33 @@ help() {
6 6
     echo "sh $0 [ adresse ] [ table ] [ id ] [ data ]\n"
7 7
 }
8 8
 
9
-if [ -z "$1" ]
9
+if [ "$1" ]
10 10
 then
11
-    echo "Missing parameters : web adresses is needed\n"
12
-    help
13
-    exit
11
+    address=$1
12
+
14 13
 fi
15
-if [ -z "$2" ]
14
+if [ "$2" ]
16 15
 then
17
-    echo "Missing parameters : tablename is needed\n"
18
-    help
19
-    exit
16
+    tablename=$2
20 17
 fi
21 18
 
22
-if [ -z "$3" ]
19
+if [ "$3" ]
23 20
 then
24
-    echo "Missing parameters : an id is needed\n"
25
-    help
26
-    exit
21
+    id=$3
27 22
 fi
28
-if [ -z "$4" ]
23
+if [ "$4" ]
29 24
 then
30
-    echo "Missing parameters : data are needed\n"
31
-    help
32
-    exit
25
+    data=$4
33 26
 fi
34 27
 
35
-echo "Set data for $2 with id $3"
36
-curl --header "Content-Type: application/json" -b cookie.txt -X PUT --data "$4" $1/api.php/records/$2/$3
28
+. ./config.sh
29
+. ./dep/address.sh
30
+. ./dep/tablename.sh
31
+. ./dep/id.sh
32
+. ./dep/data.sh
33
+
34
+. ./tools/title.sh
35
+echo "Set data for tablename with id $id"
36
+result=`curl --header "Content-Type: application/json" -b cookie.txt -X PUT --data "$data" $address/api.php/records/$tablename/$id 2>/dev/null`
37
+sh tools/show_result.sh $result
37 38
 echo "\n"

+ 6
- 0
test/test.conf View File

@@ -0,0 +1,6 @@
1
+username=nas
2
+password=starwars
3
+address=192.168.1.152:8080
4
+tablename=ticket
5
+id=1
6
+data=’{"name" : "ondoing test run", "description" : "this ticket has been added by a testscript"}’

+ 4
- 0
test/tests.sh View File

@@ -0,0 +1,4 @@
1
+#!/bin/sh
2
+
3
+sh login.sh
4
+find . -iname "*_*.sh" -type f -exec sh {} \;

+ 12
- 0
test/tools/show_result.sh View File

@@ -0,0 +1,12 @@
1
+#!/bin/sh
2
+
3
+code=`echo $1 | grep code`
4
+
5
+if [ $code ]
6
+then
7
+    echo "\e[1;31mTest : [fail]\e[0m"
8
+else
9
+    echo "\e[1;32mResult [success]\e[0m"
10
+fi
11
+
12
+

+ 3
- 0
test/tools/title.sh View File

@@ -0,0 +1,3 @@
1
+#/bin/sh
2
+echo "\e[1;34m\nTest : $0\e[0m"
3
+echo "\e[1;34m‾‾‾‾‾‾‾\e[0m"

Loading…
Cancel
Save