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
This commit is contained in:
parent
5b012e313f
commit
f6fe167278
@ -15,10 +15,9 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/}}
|
*/}}
|
||||||
|
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
function create_index () {
|
function create_test_index () {
|
||||||
index_result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
index_result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||||
-XPUT "${ELASTICSEARCH_ENDPOINT}/test_index?pretty" -H 'Content-Type: application/json' -d'
|
-XPUT "${ELASTICSEARCH_ENDPOINT}/test_index?pretty" -H 'Content-Type: application/json' -d'
|
||||||
{
|
{
|
||||||
@ -39,9 +38,9 @@ function create_index () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function insert_test_data () {
|
function insert_data_into_test_index () {
|
||||||
insert_result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
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",
|
"name" : "Elasticsearch",
|
||||||
"message" : "Test data text entry"
|
"message" : "Test data text entry"
|
||||||
@ -56,8 +55,7 @@ function insert_test_data () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function check_hits_on_test_data () {
|
||||||
function check_hits () {
|
|
||||||
total_hits=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
total_hits=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||||
"${ELASTICSEARCH_ENDPOINT}/_search?pretty" -H 'Content-Type: application/json' -d'
|
"${ELASTICSEARCH_ENDPOINT}/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||||
{
|
{
|
||||||
@ -79,6 +77,13 @@ function check_hits () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
create_index
|
function remove_test_index () {
|
||||||
insert_test_data
|
echo "Deleting index created for service testing"
|
||||||
check_hits
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user