Select the test set to run
[apps/app-templates.git] / test-wgt / launcher.sh.in
1 #!/bin/bash
2
3 ###########################################################################
4 # Copyright (C) 2017, 2018 IoT.bzh
5 #
6 # Author: Romain Forlot <romain.forlot@iot.bzh>
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 ###########################################################################
20
21 PORT=$1
22 TOKEN=$2
23
24 [ ! "${VERBSELECTED}" ] && VERBSELECTED="*"
25
26 # Research the Api name used
27 CFGFILE=$(find ${AFM_APP_INSTALL_DIR} -name "*json" -print | head -n1)
28 API=$(grep '\"api\"' ${CFGFILE} | cut -d'"' -f4)
29
30 AFBCLIENTIN=$(mktemp -u)
31 AFBCLIENTOUT=$(mktemp -u)
32 mkfifo $AFBCLIENTIN
33 mkfifo $AFBCLIENTOUT
34
35 declare -a testVerb
36
37 if [[ $(jq -r '.testVerb|type' $CFGFILE) == "array" ]]
38 then
39         testVerbLength=$(jq '.testVerb|length' $CFGFILE)
40         if [ "$VERBSELECTED" = "*" ]
41         then
42                 # Get all the verbs of the test api
43                 for (( idx=0; idx<testVerbLength; idx++ )) do
44                         testVerb[$idx]=$(jq -r ".testVerb[$idx].uid" ${CFGFILE})
45                 done
46         else
47                 # You search for a exact matching verb so there should be only one match
48                 for (( idx=0; idx<testVerbLength; idx++ )) do
49                         [ "$(jq -r ".testVerb[$idx].uid" ${CFGFILE})" = "$VERBSELECTED" ] && \
50                         testVerb[0]=$(jq -r ".testVerb[$idx].uid" ${CFGFILE})
51                 done
52         fi
53 else
54         if [ "$VERBSELECTED" = "*" ]
55         then
56                 testVerb[0]=$(jq -r ".testVerb.uid" ${CFGFILE})
57         else
58                 [ "$(jq -r ".testVerb[0].uid" ${CFGFILE})" = "$VERBSELECTED" ] && \
59                 testVerb[0]=$(jq -r ".testVerb[$idx].uid" ${CFGFILE})
60         fi
61 fi
62
63 testVerbLength=${#testVerb[@]}
64 for (( idx=0; idx<testVerbLength; idx++ )) do
65         echo "Launching ${testVerb[$idx]}"
66         afb-client-demo -s ws://localhost:${PORT}/api?token=${TOKEN} "$API" "${testVerb[$idx]}" "${VERBARGS}"
67 done
68
69 afb-client-demo ws://localhost:${PORT}/api?token=${TOKEN} "$API" "exit"