Test env updates
[nonrtric.git] / test / common / cr_api_functions.sh
index d587c0c..c19797a 100644 (file)
@@ -35,7 +35,7 @@ __CR_imagesetup() {
 # <pull-policy-original> Shall be used for images that does not allow overriding
 # Both var may contain: 'remote', 'remote-remove' or 'local'
 __CR_imagepull() {
-       echo -e $RED" Image for app CR shall never be pulled from remove repo"$ERED
+       echo -e $RED" Image for app CR shall never be pulled from remote repo"$ERED
 }
 
 # Build image (only for simulator or interfaces stubs owned by the test environment)
@@ -46,9 +46,13 @@ __CR_imagebuild() {
        echo " Building CR - $CR_DISPLAY_NAME - image: $CR_IMAGE"
        docker build  --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $CR_IMAGE . &> .dockererr
        if [ $? -eq 0 ]; then
-               echo -e  $GREEN" Build Ok"$EGREEN
+               echo -e  $GREEN"  Build Ok"$EGREEN
+               __retag_and_push_image CR_IMAGE
+               if [ $? -ne 0 ]; then
+                       exit 1
+               fi
        else
-               echo -e $RED" Build Failed"$ERED
+               echo -e $RED"  Build Failed"$ERED
                ((RES_CONF_FAIL++))
                cat .dockererr
                echo -e $RED"Exiting...."$ERED
@@ -57,9 +61,13 @@ __CR_imagebuild() {
 }
 
 # Generate a string for each included image using the app display name and a docker images format string
+# If a custom image repo is used then also the source image from the local repo is listed
 # arg: <docker-images-format-string> <file-to-append>
 __CR_image_data() {
        echo -e "$CR_DISPLAY_NAME\t$(docker images --format $1 $CR_IMAGE)" >>   $2
+       if [ ! -z "$CR_IMAGE_SOURCE" ]; then
+               echo -e "-- source image --\t$(docker images --format $1 $CR_IMAGE_SOURCE)" >>   $2
+       fi
 }
 
 # Scale kubernetes resources to zero
@@ -382,4 +390,88 @@ cr_api_check_all_ecs_events() {
        fi
        __log_test_pass
        return 0
+}
+
+# CR API: Check the contents of all current type subscription events for one id from ECS
+# <response-code> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]
+# (Function for test scripts)
+cr_api_check_all_ecs_subscription_events() {
+       __log_test_start $@
+
+       #Valid number of parameter 2,3,7,11
+       paramError=1
+       if [ $# -eq 2 ]; then
+               paramError=0
+       fi
+       if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
+               paramError=0
+       fi
+       variablecount=$(($#-2))
+       if [ $# -gt 3 ] && [ $(($variablecount%3)) -eq 0 ]; then
+               paramError=0
+       fi
+       if [ $paramError -eq 1 ]; then
+               __print_err "<response-code> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]" $@
+               return 1
+       fi
+
+       query="/get-all-events/"$2
+       res="$(__do_curl_to_api CR GET $query)"
+       status=${res:${#res}-3}
+
+       if [ $status -ne $1 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+
+       if [ $# -gt 2 ]; then
+               body=${res:0:${#res}-3}
+               targetJson="["
+               if [ $# -gt 3 ]; then
+                       arr=(${@:3})
+                       for ((i=0; i<$(($#-3)); i=i+3)); do
+                               if [ "$targetJson" != "[" ]; then
+                                       targetJson=$targetJson","
+                               fi
+                               if [ -f ${arr[$i+1]} ]; then
+                                       jobfile=$(cat ${arr[$i+1]})
+                               else
+                                       __log_test_fail_general "Job schema file "${arr[$i+1]}", does not exist"
+                                       return 1
+                               fi
+                               targetJson=$targetJson"{\"info_type_id\":\"${arr[$i]}\",\"job_data_schema\":$jobfile,\"status\":\"${arr[$i+2]}\"}"
+                       done
+               fi
+               targetJson=$targetJson"]"
+
+               echo " TARGET JSON: $targetJson" >> $HTTPLOG
+               res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+               if [ $res -ne 0 ]; then
+                       __log_test_fail_body
+                       return 1
+               fi
+       fi
+
+       __log_test_pass
+       return 0
+}
+
+
+# CR API: Reset all events and counters
+# Arg: -
+# (Function for test scripts)
+cr_api_reset() {
+       __log_conf_start $@
+
+       res="$(__do_curl_to_api CR GET /reset)"
+       status=${res:${#res}-3}
+
+       if [ $status -ne 200 ]; then
+               __log_conf_fail_status_code $1 $status
+               return 1
+       fi
+
+       __log_conf_ok
+       return 0
 }
\ No newline at end of file