From cb750fc9a832227d524d3bf07d889d444a8937b2 Mon Sep 17 00:00:00 2001 From: Michael Folz Date: Wed, 15 Jan 2025 14:16:09 +0100 Subject: [PATCH] #428 - Read document ids from downloaded files in github integration tests - use grep/awk to extract the first id from an ontology and a codeable_concept file to use for checks --- .github/scripts/post-elastic-test-queries.sh | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/.github/scripts/post-elastic-test-queries.sh b/.github/scripts/post-elastic-test-queries.sh index 01a9f0a6..4c0ef75f 100755 --- a/.github/scripts/post-elastic-test-queries.sh +++ b/.github/scripts/post-elastic-test-queries.sh @@ -1,6 +1,44 @@ #!/bin/bash -e curl "$ELASTIC_HOST/_cat/indices" +ls -la +ls -la elastic + +onto_example_id=$(grep '"_id":' ./elastic/onto_es__ontology_* | awk -F'"_id": "' '{print $2}' | awk -F'"' '{print $1}' | head -n 1) +cc_example_id=$(grep '"_id":' ./elastic/onto_es__codeable_concept_* | awk -F'"_id": "' '{print $2}' | awk -F'"' '{print $1}' | head -n 1) + +response=$(curl -s -w "%{http_code}" -o response_body "$ELASTIC_HOST/ontology/_doc/$onto_example_id") +http_code="${response: -3}" +json_body=$(cat response_body) + +if [ "$http_code" -eq 200 ]; then + if echo "$json_body" | jq '.found == true' | grep -q true; then + echo "Ontology Document with id $onto_example_id found in elastic search" + else + echo "Empty or nonexistent response from elastic search for ontology document with id $onto_example_id" + exit 1 + fi +else + echo "Response code $http_code" + exit 1 +fi + + +response=$(curl -s -w "%{http_code}" -o response_body "$ELASTIC_HOST/codeable_concept/_doc/$cc_example_id") +http_code="${response: -3}" +json_body=$(cat response_body) + +if [ "$http_code" -eq 200 ]; then + if echo "$json_body" | jq '.found == true' | grep -q true; then + echo "Codeable Concept Document with id $cc_example_id found in elastic search" + else + echo "Empty or nonexistent response from elastic search for codeable_concept document with id $cc_example_id" + exit 1 + fi +else + echo "Response code $http_code" + exit 1 +fi access_token="$(curl -s --request POST \ --url http://localhost:8083/auth/realms/dataportal/protocol/openid-connect/token \ @@ -17,6 +55,22 @@ json_body=$(cat response_body) if [ "$http_code" -eq 200 ]; then if echo "$json_body" | jq '.totalHits > 0' | grep -q true; then + echo "OK response with non-empty array on onto search with searchterm" + else + echo "Empty or nonexistent response on onto search with searchterm" + exit 1 + fi +else + echo "Response code $http_code" + exit 1 +fi + +response=$(curl -s -w "%{http_code}" --header "Authorization: Bearer $access_token" -o response_body "http://localhost:8091/api/v4/terminology/entry/$onto_example_id") +http_code="${response: -3}" +json_body=$(cat response_body) + +if [ "$http_code" -eq 200 ]; then + if echo "$json_body" | jq -e '.termcode and .termcode != ""' | grep -q true; then echo "OK response with non-empty array" else echo "Empty or nonexistent response" @@ -43,5 +97,21 @@ else exit 1 fi +response=$(curl -s -w "%{http_code}" --header "Authorization: Bearer $access_token" -o response_body "http://localhost:8091/api/v4/codeable-concept/entry/$cc_example_id") +http_code="${response: -3}" +json_body=$(cat response_body) + +if [ "$http_code" -eq 200 ]; then + if echo "$json_body" | jq -e '.code and .code != ""' | grep -q true; then + echo "OK response with non-empty array" + else + echo "Empty or nonexistent response" + exit 1 + fi +else + echo "Response code $http_code" + exit 1 +fi + echo "All elastic search tests completed" exit 0 \ No newline at end of file