BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
| 4 | # Copyright (C) 2020 Nordix Foundation. All rights reserved. |
| 5 | # ======================================================================== |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END================================================= |
| 18 | # |
| 19 | |
| 20 | # This is a script that contains specific test functions for ECS NB/SB API |
| 21 | |
| 22 | . ../common/api_curl.sh |
| 23 | |
| 24 | ############### EXPERIMENTAL ############# |
| 25 | |
| 26 | ########################################## |
| 27 | ###### Mainly only function skeletons #### |
| 28 | ########################################## |
| 29 | |
| 30 | ########################################## |
| 31 | ### A1-E Enrichment Data Consumer API #### |
| 32 | ########################################## |
| 33 | #Function prefix: ecs_api_a1 |
| 34 | |
| 35 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 36 | # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 37 | # (Function for test scripts) |
| 38 | ecs_api_a1_get_job_ids() { |
| 39 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 40 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 41 | ((RES_TEST++)) |
| 42 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 43 | # Valid number of parameters 3,4,5,6 etc |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 44 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 45 | __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 46 | return 1 |
| 47 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 48 | owner="" |
| 49 | if [ $3 != "NOWNER" ]; then |
| 50 | owner="?owner="$3 |
| 51 | fi |
| 52 | |
| 53 | query="/A1-EI/v1/eitypes/$2/eijobs$owner" |
| 54 | res="$(__do_curl_to_api ECS GET $query)" |
| 55 | status=${res:${#res}-3} |
| 56 | |
| 57 | if [ $status -ne $1 ]; then |
| 58 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 59 | ((RES_FAIL++)) |
| 60 | __check_stop_at_error |
| 61 | return 1 |
| 62 | fi |
| 63 | |
| 64 | if [ $# -gt 3 ]; then |
| 65 | body=${res:0:${#res}-3} |
| 66 | targetJson="[" |
| 67 | |
| 68 | for pid in ${@:4} ; do |
| 69 | if [ "$targetJson" != "[" ]; then |
| 70 | targetJson=$targetJson"," |
| 71 | fi |
| 72 | if [ $pid != "EMPTY" ]; then |
| 73 | targetJson=$targetJson"\"$pid\"" |
| 74 | fi |
| 75 | done |
| 76 | |
| 77 | targetJson=$targetJson"]" |
| 78 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 79 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 80 | |
| 81 | if [ $res -ne 0 ]; then |
| 82 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 83 | ((RES_FAIL++)) |
| 84 | __check_stop_at_error |
| 85 | return 1 |
| 86 | fi |
| 87 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 88 | |
| 89 | ((RES_PASS++)) |
| 90 | echo -e $GREEN" PASS"$EGREEN |
| 91 | return 0 |
| 92 | } |
| 93 | |
| 94 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 95 | # args: <response-code> <type-id> [<schema-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 96 | # (Function for test scripts) |
| 97 | ecs_api_a1_get_type() { |
| 98 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 99 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 100 | ((RES_TEST++)) |
| 101 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 102 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 103 | __print_err "<response-code> <type-id> [<schema-file>]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 104 | return 1 |
| 105 | fi |
| 106 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 107 | query="/A1-EI/v1/eitypes/$2" |
| 108 | res="$(__do_curl_to_api ECS GET $query)" |
| 109 | status=${res:${#res}-3} |
| 110 | |
| 111 | if [ $status -ne $1 ]; then |
| 112 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 113 | ((RES_FAIL++)) |
| 114 | __check_stop_at_error |
| 115 | return 1 |
| 116 | fi |
| 117 | |
| 118 | if [ $# -eq 3 ]; then |
| 119 | body=${res:0:${#res}-3} |
| 120 | if [ -f $3 ]; then |
| 121 | schema=$(cat $3) |
| 122 | else |
| 123 | echo -e $RED" FAIL. Schema file "$3", does not exist"$ERED |
| 124 | ((RES_FAIL++)) |
| 125 | __check_stop_at_error |
| 126 | return 1 |
| 127 | fi |
| 128 | targetJson="{\"eiJobParametersSchema\":$schema}" |
| 129 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 130 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 131 | |
| 132 | if [ $res -ne 0 ]; then |
| 133 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 134 | ((RES_FAIL++)) |
| 135 | __check_stop_at_error |
| 136 | return 1 |
| 137 | fi |
| 138 | fi |
| 139 | |
| 140 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 141 | ((RES_PASS++)) |
| 142 | echo -e $GREEN" PASS"$EGREEN |
| 143 | return 0 |
| 144 | } |
| 145 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 146 | # API Test function: GET /A1-EI/v1/eitypes |
| 147 | # args: <response-code> [ (EMPTY | [<type-id>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 148 | # (Function for test scripts) |
| 149 | ecs_api_a1_get_type_ids() { |
| 150 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 151 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 152 | ((RES_TEST++)) |
| 153 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 154 | if [ $# -lt 1 ]; then |
| 155 | __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 156 | return 1 |
| 157 | fi |
| 158 | |
| 159 | query="/A1-EI/v1/eitypes" |
| 160 | res="$(__do_curl_to_api ECS GET $query)" |
| 161 | status=${res:${#res}-3} |
| 162 | |
| 163 | if [ $status -ne $1 ]; then |
| 164 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 165 | ((RES_FAIL++)) |
| 166 | __check_stop_at_error |
| 167 | return 1 |
| 168 | fi |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 169 | if [ $# -gt 1 ]; then |
| 170 | body=${res:0:${#res}-3} |
| 171 | targetJson="[" |
| 172 | if [ $2 != "EMPTY" ]; then |
| 173 | for pid in ${@:2} ; do |
| 174 | if [ "$targetJson" != "[" ]; then |
| 175 | targetJson=$targetJson"," |
| 176 | fi |
| 177 | targetJson=$targetJson"\"$pid\"" |
| 178 | done |
| 179 | fi |
| 180 | targetJson=$targetJson"]" |
| 181 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 182 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 183 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 184 | if [ $res -ne 0 ]; then |
| 185 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 186 | ((RES_FAIL++)) |
| 187 | __check_stop_at_error |
| 188 | return 1 |
| 189 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 190 | fi |
| 191 | |
| 192 | ((RES_PASS++)) |
| 193 | echo -e $GREEN" PASS"$EGREEN |
| 194 | return 0 |
| 195 | } |
| 196 | |
| 197 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 198 | # args: <response-code> <type-id> <job-id> [<status>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 199 | # (Function for test scripts) |
| 200 | ecs_api_a1_get_job_status() { |
| 201 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 202 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 203 | ((RES_TEST++)) |
| 204 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 205 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
| 206 | __print_err "<response-code> <type-id> <job-id>" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 207 | return 1 |
| 208 | fi |
| 209 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 210 | query="/A1-EI/v1/eitypes/$2/eijobs/$3/status" |
| 211 | res="$(__do_curl_to_api ECS GET $query)" |
| 212 | status=${res:${#res}-3} |
| 213 | |
| 214 | if [ $status -ne $1 ]; then |
| 215 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 216 | ((RES_FAIL++)) |
| 217 | __check_stop_at_error |
| 218 | return 1 |
| 219 | fi |
| 220 | if [ $# -eq 4 ]; then |
| 221 | body=${res:0:${#res}-3} |
| 222 | targetJson="{\"operationalState\": \"$4\"}" |
| 223 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 224 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 225 | |
| 226 | if [ $res -ne 0 ]; then |
| 227 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 228 | ((RES_FAIL++)) |
| 229 | __check_stop_at_error |
| 230 | return 1 |
| 231 | fi |
| 232 | fi |
| 233 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 234 | ((RES_PASS++)) |
| 235 | echo -e $GREEN" PASS"$EGREEN |
| 236 | return 0 |
| 237 | } |
| 238 | |
| 239 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 240 | # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 241 | # (Function for test scripts) |
| 242 | ecs_api_a1_get_job() { |
| 243 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 244 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 245 | ((RES_TEST++)) |
| 246 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 247 | if [ $# -ne 3 ] && [ $# -ne 6 ]; then |
| 248 | __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 249 | return 1 |
| 250 | fi |
| 251 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 252 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 253 | res="$(__do_curl_to_api ECS GET $query)" |
| 254 | status=${res:${#res}-3} |
| 255 | |
| 256 | if [ $status -ne $1 ]; then |
| 257 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 258 | ((RES_FAIL++)) |
| 259 | __check_stop_at_error |
| 260 | return 1 |
| 261 | fi |
| 262 | |
| 263 | if [ $# -eq 6 ]; then |
| 264 | body=${res:0:${#res}-3} |
| 265 | |
| 266 | if [ -f $6 ]; then |
| 267 | jobfile=$(cat $6) |
| 268 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 269 | else |
| 270 | echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED |
| 271 | ((RES_FAIL++)) |
| 272 | __check_stop_at_error |
| 273 | return 1 |
| 274 | fi |
| 275 | targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 276 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 277 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 278 | |
| 279 | if [ $res -ne 0 ]; then |
| 280 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 281 | ((RES_FAIL++)) |
| 282 | __check_stop_at_error |
| 283 | return 1 |
| 284 | fi |
| 285 | fi |
| 286 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 287 | ((RES_PASS++)) |
| 288 | echo -e $GREEN" PASS"$EGREEN |
| 289 | return 0 |
| 290 | } |
| 291 | |
| 292 | # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 293 | # args: <response-code> <type-id> <job-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 294 | # (Function for test scripts) |
| 295 | ecs_api_a1_delete_job() { |
| 296 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 297 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 298 | ((RES_TEST++)) |
| 299 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 300 | if [ $# -lt 3 ]; then |
| 301 | __print_err "<response-code> <type-id> <job-id>" $@ |
| 302 | return 1 |
| 303 | fi |
| 304 | |
| 305 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 306 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 307 | status=${res:${#res}-3} |
| 308 | |
| 309 | if [ $status -ne $1 ]; then |
| 310 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 311 | ((RES_FAIL++)) |
| 312 | __check_stop_at_error |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 313 | return 1 |
| 314 | fi |
| 315 | |
| 316 | ((RES_PASS++)) |
| 317 | echo -e $GREEN" PASS"$EGREEN |
| 318 | return 0 |
| 319 | } |
| 320 | |
| 321 | # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 322 | # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 323 | # (Function for test scripts) |
| 324 | ecs_api_a1_put_job() { |
| 325 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 326 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 327 | ((RES_TEST++)) |
| 328 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 329 | if [ $# -lt 6 ]; then |
| 330 | __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@ |
| 331 | return 1 |
| 332 | fi |
| 333 | if [ -f $6 ]; then |
| 334 | jobfile=$(cat $6) |
| 335 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 336 | else |
| 337 | echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED |
| 338 | ((RES_FAIL++)) |
| 339 | __check_stop_at_error |
| 340 | return 1 |
| 341 | fi |
| 342 | |
| 343 | inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 344 | file="./tmp/.p.json" |
| 345 | echo "$inputJson" > $file |
| 346 | |
| 347 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 348 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 349 | status=${res:${#res}-3} |
| 350 | |
| 351 | if [ $status -ne $1 ]; then |
| 352 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 353 | ((RES_FAIL++)) |
| 354 | __check_stop_at_error |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 355 | return 1 |
| 356 | fi |
| 357 | |
| 358 | ((RES_PASS++)) |
| 359 | echo -e $GREEN" PASS"$EGREEN |
| 360 | return 0 |
| 361 | } |
| 362 | |
| 363 | |
| 364 | ########################################## |
| 365 | #### Enrichment Data Producer API #### |
| 366 | ########################################## |
| 367 | # Function prefix: ecs_api_edp |
| 368 | |
| 369 | # API Test function: GET /ei-producer/v1/eitypes |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 370 | # args: <response-code> [ EMPTY | <type-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 371 | # (Function for test scripts) |
| 372 | ecs_api_edp_get_type_ids() { |
| 373 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 374 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 375 | ((RES_TEST++)) |
| 376 | |
| 377 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 378 | __print_err "<response-code> [ EMPTY | <type-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 379 | return 1 |
| 380 | fi |
| 381 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 382 | query="/ei-producer/v1/eitypes" |
| 383 | res="$(__do_curl_to_api ECS GET $query)" |
| 384 | status=${res:${#res}-3} |
| 385 | |
| 386 | if [ $status -ne $1 ]; then |
| 387 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 388 | ((RES_FAIL++)) |
| 389 | __check_stop_at_error |
| 390 | return 1 |
| 391 | fi |
| 392 | |
| 393 | if [ $# -gt 1 ]; then |
| 394 | body=${res:0:${#res}-3} |
| 395 | targetJson="[" |
| 396 | if [ $2 != "EMPTY" ]; then |
| 397 | for pid in ${@:2} ; do |
| 398 | if [ "$targetJson" != "[" ]; then |
| 399 | targetJson=$targetJson"," |
| 400 | fi |
| 401 | targetJson=$targetJson"\"$pid\"" |
| 402 | done |
| 403 | fi |
| 404 | targetJson=$targetJson"]" |
| 405 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 406 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 407 | |
| 408 | if [ $res -ne 0 ]; then |
| 409 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 410 | ((RES_FAIL++)) |
| 411 | __check_stop_at_error |
| 412 | return 1 |
| 413 | fi |
| 414 | fi |
| 415 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 416 | ((RES_PASS++)) |
| 417 | echo -e $GREEN" PASS"$EGREEN |
| 418 | return 0 |
| 419 | } |
| 420 | |
| 421 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 422 | # args: <response-code> <producer-id> [<status>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 423 | # (Function for test scripts) |
| 424 | ecs_api_edp_get_producer_status() { |
| 425 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 426 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 427 | ((RES_TEST++)) |
| 428 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 429 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 430 | __print_err "<response-code> <producer-id> [<status>]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 431 | return 1 |
| 432 | fi |
| 433 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 434 | query="/ei-producer/v1/eiproducers/$2/status" |
| 435 | res="$(__do_curl_to_api ECS GET $query)" |
| 436 | status=${res:${#res}-3} |
| 437 | |
| 438 | if [ $status -ne $1 ]; then |
| 439 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 440 | ((RES_FAIL++)) |
| 441 | __check_stop_at_error |
| 442 | return 1 |
| 443 | fi |
| 444 | if [ $# -eq 3 ]; then |
| 445 | body=${res:0:${#res}-3} |
| 446 | targetJson="{\"operational_state\": \"$3\"}" |
| 447 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 448 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 449 | |
| 450 | if [ $res -ne 0 ]; then |
| 451 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 452 | ((RES_FAIL++)) |
| 453 | __check_stop_at_error |
| 454 | return 1 |
| 455 | fi |
| 456 | fi |
| 457 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 458 | ((RES_PASS++)) |
| 459 | echo -e $GREEN" PASS"$EGREEN |
| 460 | return 0 |
| 461 | } |
| 462 | |
| 463 | |
| 464 | # API Test function: GET /ei-producer/v1/eiproducers |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 465 | # args: <response-code> [ EMPTY | <producer-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 466 | # (Function for test scripts) |
| 467 | ecs_api_edp_get_producer_ids() { |
| 468 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 469 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 470 | ((RES_TEST++)) |
| 471 | |
| 472 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 473 | __print_err "<response-code> [ EMPTY | <producer-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 474 | return 1 |
| 475 | fi |
| 476 | |
| 477 | query="/ei-producer/v1/eiproducers" |
| 478 | res="$(__do_curl_to_api ECS GET $query)" |
| 479 | status=${res:${#res}-3} |
| 480 | |
| 481 | if [ $status -ne $1 ]; then |
| 482 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 483 | ((RES_FAIL++)) |
| 484 | __check_stop_at_error |
| 485 | return 1 |
| 486 | fi |
| 487 | |
| 488 | if [ $# -gt 1 ]; then |
| 489 | body=${res:0:${#res}-3} |
| 490 | targetJson="[" |
| 491 | |
| 492 | for pid in ${@:2} ; do |
| 493 | if [ "$targetJson" != "[" ]; then |
| 494 | targetJson=$targetJson"," |
| 495 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 496 | if [ $pid != "EMPTY" ]; then |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 497 | targetJson=$targetJson"\"$pid\"" |
| 498 | fi |
| 499 | done |
| 500 | |
| 501 | targetJson=$targetJson"]" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 502 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 503 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 504 | |
| 505 | if [ $res -ne 0 ]; then |
| 506 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 507 | ((RES_FAIL++)) |
| 508 | __check_stop_at_error |
| 509 | return 1 |
| 510 | fi |
| 511 | fi |
| 512 | |
| 513 | ((RES_PASS++)) |
| 514 | echo -e $GREEN" PASS"$EGREEN |
| 515 | return 0 |
| 516 | } |
| 517 | |
| 518 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 519 | # args: <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 520 | # (Function for test scripts) |
| 521 | ecs_api_edp_get_type() { |
| 522 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 523 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 524 | ((RES_TEST++)) |
| 525 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 526 | paramError=1 |
| 527 | if [ $# -eq 2 ]; then |
| 528 | paramError=0 |
| 529 | fi |
| 530 | if [ $# -gt 3 ]; then |
| 531 | paramError=0 |
| 532 | fi |
| 533 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 534 | __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 535 | return 1 |
| 536 | fi |
| 537 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 538 | query="/ei-producer/v1/eitypes/$2" |
| 539 | res="$(__do_curl_to_api ECS GET $query)" |
| 540 | status=${res:${#res}-3} |
| 541 | |
| 542 | if [ $status -ne $1 ]; then |
| 543 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 544 | ((RES_FAIL++)) |
| 545 | __check_stop_at_error |
| 546 | return 1 |
| 547 | fi |
| 548 | if [ $# -gt 3 ]; then |
| 549 | body=${res:0:${#res}-3} |
| 550 | |
| 551 | if [ -f $3 ]; then |
| 552 | schema=$(cat $3) |
| 553 | else |
| 554 | echo -e $RED" FAIL. Job template file "$3", does not exist"$ERED |
| 555 | ((RES_FAIL++)) |
| 556 | __check_stop_at_error |
| 557 | return 1 |
| 558 | fi |
| 559 | |
| 560 | targetJson="" |
| 561 | if [ $4 != "EMPTY" ]; then |
| 562 | for pid in ${@:4} ; do |
| 563 | if [ "$targetJson" != "" ]; then |
| 564 | targetJson=$targetJson"," |
| 565 | fi |
| 566 | targetJson=$targetJson"\"$pid\"" |
| 567 | done |
| 568 | fi |
| 569 | targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}" |
| 570 | |
| 571 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 572 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 573 | |
| 574 | if [ $res -ne 0 ]; then |
| 575 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 576 | ((RES_FAIL++)) |
| 577 | __check_stop_at_error |
| 578 | return 1 |
| 579 | fi |
| 580 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 581 | ((RES_PASS++)) |
| 582 | echo -e $GREEN" PASS"$EGREEN |
| 583 | return 0 |
| 584 | } |
| 585 | |
| 586 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 587 | # args: <response-code> <producer-id> [<create-callback> <delete-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 588 | # (Function for test scripts) |
| 589 | ecs_api_edp_get_producer() { |
| 590 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 591 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 592 | ((RES_TEST++)) |
| 593 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 594 | #Possible arg count: 2, 6 7, 9, 11 etc |
| 595 | paramError=1 |
| 596 | if [ $# -eq 2 ]; then |
| 597 | paramError=0 |
| 598 | fi |
| 599 | if [ $# -eq 6 ] && [ "$6" == "EMPTY" ]; then |
| 600 | paramError=0 |
| 601 | fi |
| 602 | variablecount=$(($#-5)) |
| 603 | if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then |
| 604 | paramError=0 |
| 605 | fi |
| 606 | |
| 607 | if [ $paramError -ne 0 ]; then |
| 608 | __print_err "<response-code> <producer-id> [<create-callback> <delete-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 609 | return 1 |
| 610 | fi |
| 611 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 612 | query="/ei-producer/v1/eiproducers/$2" |
| 613 | res="$(__do_curl_to_api ECS GET $query)" |
| 614 | status=${res:${#res}-3} |
| 615 | |
| 616 | if [ $status -ne $1 ]; then |
| 617 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 618 | ((RES_FAIL++)) |
| 619 | __check_stop_at_error |
| 620 | return 1 |
| 621 | fi |
| 622 | |
| 623 | if [ $# -gt 2 ]; then |
| 624 | body=${res:0:${#res}-3} |
| 625 | targetJson="[" |
| 626 | if [ $# -gt 6 ]; then |
| 627 | arr=(${@:6}) |
| 628 | for ((i=0; i<$(($#-6)); i=i+2)); do |
| 629 | if [ "$targetJson" != "[" ]; then |
| 630 | targetJson=$targetJson"," |
| 631 | fi |
| 632 | if [ -f ${arr[$i+1]} ]; then |
| 633 | schema=$(cat ${arr[$i+1]}) |
| 634 | else |
| 635 | echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED |
| 636 | ((RES_FAIL++)) |
| 637 | __check_stop_at_error |
| 638 | return 1 |
| 639 | fi |
| 640 | |
| 641 | targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 642 | done |
| 643 | fi |
| 644 | targetJson=$targetJson"]" |
| 645 | if [ $# -gt 4 ]; then |
| 646 | targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"}" |
| 647 | fi |
| 648 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 649 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 650 | |
| 651 | if [ $res -ne 0 ]; then |
| 652 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 653 | ((RES_FAIL++)) |
| 654 | __check_stop_at_error |
| 655 | return 1 |
| 656 | fi |
| 657 | fi |
| 658 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 659 | ((RES_PASS++)) |
| 660 | echo -e $GREEN" PASS"$EGREEN |
| 661 | return 0 |
| 662 | } |
| 663 | |
| 664 | # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 665 | # args: <response-code> <producer-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 666 | # (Function for test scripts) |
| 667 | ecs_api_edp_delete_producer() { |
| 668 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 669 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 670 | ((RES_TEST++)) |
| 671 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 672 | if [ $# -lt 2 ]; then |
| 673 | __print_err "<response-code> <producer-id>" $@ |
| 674 | return 1 |
| 675 | fi |
| 676 | |
| 677 | query="/ei-producer/v1/eiproducers/$2" |
| 678 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 679 | status=${res:${#res}-3} |
| 680 | |
| 681 | if [ $status -ne $1 ]; then |
| 682 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 683 | ((RES_FAIL++)) |
| 684 | __check_stop_at_error |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 685 | return 1 |
| 686 | fi |
| 687 | |
| 688 | ((RES_PASS++)) |
| 689 | echo -e $GREEN" PASS"$EGREEN |
| 690 | return 0 |
| 691 | } |
| 692 | |
| 693 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 694 | # args: <response-code> <producer-id> <create-callback> <delete-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 695 | # (Function for test scripts) |
| 696 | ecs_api_edp_put_producer() { |
| 697 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 698 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 699 | ((RES_TEST++)) |
| 700 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 701 | #Valid number of parametrer 6,7,9,11, |
| 702 | paramError=1 |
| 703 | if [ $# -eq 6 ] && [ "$6" == "NOTYPE" ]; then |
| 704 | paramError=0 |
| 705 | elif [ $# -gt 6 ] && [ $(($#%2)) -eq 1 ]; then |
| 706 | paramError=0 |
| 707 | fi |
| 708 | if [ $paramError -ne 0 ]; then |
| 709 | __print_err "<response-code> <producer-id> <create-callback> <delete-callback> <supervision-callback> [<type-id> <schema-file>]+" $@ |
| 710 | return 1 |
| 711 | fi |
| 712 | |
| 713 | inputJson="[" |
| 714 | if [ $# -gt 6 ]; then |
| 715 | arr=(${@:6}) |
| 716 | for ((i=0; i<$(($#-6)); i=i+2)); do |
| 717 | if [ "$inputJson" != "[" ]; then |
| 718 | inputJson=$inputJson"," |
| 719 | fi |
| 720 | if [ -f ${arr[$i+1]} ]; then |
| 721 | schema=$(cat ${arr[$i+1]}) |
| 722 | else |
| 723 | echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED |
| 724 | ((RES_FAIL++)) |
| 725 | __check_stop_at_error |
| 726 | return 1 |
| 727 | fi |
| 728 | inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 729 | done |
| 730 | fi |
| 731 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 732 | |
| 733 | inputJson=$inputJson",\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"" |
| 734 | |
| 735 | inputJson="{"$inputJson"}" |
| 736 | |
| 737 | file="./tmp/.p.json" |
| 738 | echo "$inputJson" > $file |
| 739 | query="/ei-producer/v1/eiproducers/$2" |
| 740 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 741 | status=${res:${#res}-3} |
| 742 | |
| 743 | if [ $status -ne $1 ]; then |
| 744 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 745 | ((RES_FAIL++)) |
| 746 | __check_stop_at_error |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 747 | return 1 |
| 748 | fi |
| 749 | |
| 750 | ((RES_PASS++)) |
| 751 | echo -e $GREEN" PASS"$EGREEN |
| 752 | return 0 |
| 753 | } |
| 754 | |
| 755 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 756 | # args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <template-job-file>]+) |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 757 | # (Function for test scripts) |
| 758 | ecs_api_edp_get_producer_jobs() { |
| 759 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 760 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 761 | ((RES_TEST++)) |
| 762 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 763 | #Valid number of parameter 2,3,6,10 |
| 764 | paramError=1 |
| 765 | if [ $# -eq 2 ]; then |
| 766 | paramError=0 |
| 767 | fi |
| 768 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 769 | paramError=0 |
| 770 | fi |
| 771 | variablecount=$(($#-2)) |
| 772 | if [ $# -gt 3 ] && [ $(($variablecount%4)) -eq 0 ]; then |
| 773 | paramError=0 |
| 774 | fi |
| 775 | if [ $paramError -eq 1 ]; then |
| 776 | __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <template-job-file>]+)" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 777 | return 1 |
| 778 | fi |
| 779 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 780 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
| 781 | res="$(__do_curl_to_api ECS GET $query)" |
| 782 | status=${res:${#res}-3} |
| 783 | if [ $status -ne $1 ]; then |
| 784 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 785 | ((RES_FAIL++)) |
| 786 | __check_stop_at_error |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 787 | return 1 |
| 788 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 789 | if [ $# -gt 2 ]; then |
| 790 | body=${res:0:${#res}-3} |
| 791 | targetJson="[" |
| 792 | if [ $# -gt 3 ]; then |
| 793 | arr=(${@:3}) |
| 794 | for ((i=0; i<$(($#-3)); i=i+4)); do |
| 795 | if [ "$targetJson" != "[" ]; then |
| 796 | targetJson=$targetJson"," |
| 797 | fi |
| 798 | if [ -f ${arr[$i+3]} ]; then |
| 799 | jobfile=$(cat ${arr[$i+3]}) |
| 800 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 801 | else |
| 802 | echo -e $RED" FAIL. Job template file "${arr[$i+3]}", does not exist"$ERED |
| 803 | ((RES_FAIL++)) |
| 804 | __check_stop_at_error |
| 805 | return 1 |
| 806 | fi |
| 807 | targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"ei_job_data\":$jobfile}" |
| 808 | done |
| 809 | fi |
| 810 | targetJson=$targetJson"]" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 811 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 812 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 813 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 814 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 815 | if [ $res -ne 0 ]; then |
| 816 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 817 | ((RES_FAIL++)) |
| 818 | __check_stop_at_error |
| 819 | return 1 |
| 820 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 821 | fi |
| 822 | |
| 823 | ((RES_PASS++)) |
| 824 | echo -e $GREEN" PASS"$EGREEN |
| 825 | return 0 |
| 826 | } |
| 827 | |
| 828 | |
| 829 | ########################################## |
| 830 | #### Service status #### |
| 831 | ########################################## |
| 832 | # Function prefix: ecs_api_service |
| 833 | |
| 834 | # API Test function: GET /status |
| 835 | # args: <response-code> |
| 836 | # (Function for test scripts) |
| 837 | ecs_api_service_status() { |
| 838 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 839 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 840 | ((RES_TEST++)) |
| 841 | |
| 842 | if [ $# -lt 1 ]; then |
| 843 | __print_err "<response-code> [<producer-id>]*|NOID" $@ |
| 844 | return 1 |
| 845 | fi |
| 846 | |
| 847 | ((RES_PASS++)) |
| 848 | echo -e $GREEN" PASS"$EGREEN |
| 849 | return 0 |
| 850 | } |