From f6fe1672785f6233df2fe2be5fcc1fe2ce7bde12 Mon Sep 17 00:00:00 2001 From: Steve Wilkerson Date: Wed, 6 Jun 2018 14:23:37 -0500 Subject: [PATCH] Elasticsearch: Update tests to clean up test data and index This ps adds a function for cleaning up the test data used to verify Elasticsearch is functioning properly. It removes the test index created and populated with test data to ensure the resulting elasticsearch cluster is clean and does not contain random data Change-Id: Ibdeb90e3f3b6307bf16c68469556bef256ed2d78 --- .../templates/bin/_helm-tests.sh.tpl | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/elasticsearch/templates/bin/_helm-tests.sh.tpl b/elasticsearch/templates/bin/_helm-tests.sh.tpl index 20e16eca2..817689d0f 100644 --- a/elasticsearch/templates/bin/_helm-tests.sh.tpl +++ b/elasticsearch/templates/bin/_helm-tests.sh.tpl @@ -15,10 +15,9 @@ See the License for the specific language governing permissions and limitations under the License. */}} - set -ex -function create_index () { +function create_test_index () { index_result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ -XPUT "${ELASTICSEARCH_ENDPOINT}/test_index?pretty" -H 'Content-Type: application/json' -d' { @@ -39,9 +38,9 @@ function create_index () { fi } -function insert_test_data () { +function insert_data_into_test_index () { insert_result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ - -XPUT "${ELASTICSEARCH_ENDPOINT}/sample_index/sample_type/123/_create?pretty" -H 'Content-Type: application/json' -d' + -XPUT "${ELASTICSEARCH_ENDPOINT}/test_index/sample_type/123/_create?pretty" -H 'Content-Type: application/json' -d' { "name" : "Elasticsearch", "message" : "Test data text entry" @@ -56,8 +55,7 @@ function insert_test_data () { fi } - -function check_hits () { +function check_hits_on_test_data () { total_hits=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ "${ELASTICSEARCH_ENDPOINT}/_search?pretty" -H 'Content-Type: application/json' -d' { @@ -79,6 +77,13 @@ function check_hits () { fi } -create_index -insert_test_data -check_hits +function remove_test_index () { + echo "Deleting index created for service testing" + curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ + -XDELETE "${ELASTICSEARCH_ENDPOINT}/test_index" +} + +create_test_index +insert_data_into_test_index +check_hits_on_test_data +remove_test_index