From 01247ae744fc42bf38465da8870171cbe92a377a Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Mon, 6 Jul 2026 14:16:12 +0200 Subject: [PATCH] add more tests --- Makefile | 5 ++--- t/.env | 15 +-------------- t/Makefile | 7 +++++-- t/README.md | 2 +- t/cluster.yaml | 1 - t/docker-compose.yaml | 10 +++++----- t/msc-actions.yaml | 32 ++++++++++++++++++++++++++++++-- t/msc-cluster.yaml | 22 +++++++++++++++++++++- t/msc-docs.yaml | 5 ++++- t/msc-search.yaml | 17 +++++++++++------ 10 files changed, 80 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 8a6c325..66ac406 100644 --- a/Makefile +++ b/Makefile @@ -62,9 +62,8 @@ install: buildlocal clean: rm -rf $(tool) coverage.out testdata t/out pkg/es/openspec.go -test: clean - mkdir -p t/out - go test ./... $(ARGS) +test: clean buildlocal + make -C t test testlint: test lint diff --git a/t/.env b/t/.env index 1474cc5..3451b73 100644 --- a/t/.env +++ b/t/.env @@ -1,19 +1,6 @@ -# Password for the 'elastic' user (at least 6 characters) -ELASTIC_PASSWORD=tuscador1 - -# Version of Elastic products +ES_PASS=tuscador1 STACK_VERSION=9.4.2 - -# Set the cluster name CLUSTER_NAME=domdoc - -# Set to 'basic' or 'trial' to automatically start the 30-day trial LICENSE=basic -#LICENSE=trial - -# Port to expose Elasticsearch HTTP API to the host ES_PORT=9200 -#ES_PORT=127.0.0.1:9200 - -# Increase or decrease based on the available host memory (in bytes) MEM_LIMIT=1073741824 diff --git a/t/Makefile b/t/Makefile index dadf3a5..7f90f67 100644 --- a/t/Makefile +++ b/t/Makefile @@ -21,7 +21,7 @@ clean-docker: down delete # mosscap esctl stuff -test: up waitup cluster docs search +test: up waitup cluster docs wait search cluster: @echo "setting up elastisearch cluster" @@ -31,9 +31,12 @@ docs: @echo "put some docs" mosscap msc-actions.yaml msc-docs.yaml -n -c 1000 -p 100 +wait: + sleep 10 + search: @echo "make some searches" - mosscap msc-actions.yaml msc-search.yaml -n + mosscap msc-actions.yaml msc-search.yaml -n -t 60 clean: @echo "cleaning up cluster" diff --git a/t/README.md b/t/README.md index 20d8d31..e0156b6 100644 --- a/t/README.md +++ b/t/README.md @@ -13,7 +13,7 @@ The following is required: - linux, any distro will do - docker in a decent version -- [mosscap](https://codeberg.org/scip/mosscap) +- [mosscap](https://codeberg.org/scip/mosscap) version `0.0.17` or higher. # Docker diff --git a/t/cluster.yaml b/t/cluster.yaml index 9b7bcad..9fba3b9 100644 --- a/t/cluster.yaml +++ b/t/cluster.yaml @@ -3,6 +3,5 @@ clusters: docker/domdoc: uri: https://elastic:9200 user: elastic - pass: tuscador1 token: "" default: false diff --git a/t/docker-compose.yaml b/t/docker-compose.yaml index 2ab497c..fced04e 100644 --- a/t/docker-compose.yaml +++ b/t/docker-compose.yaml @@ -6,8 +6,8 @@ services: user: "0" command: > bash -c ' - if [ x${ELASTIC_PASSWORD} == x ]; then - echo "Set the ELASTIC_PASSWORD environment variable in the .env file"; + if [ x${ES_PASS} == x ]; then + echo "Set the ES_PASS environment variable in the .env file"; exit 1; fi; if [ ! -f config/certs/ca.zip ]; then @@ -70,7 +70,7 @@ services: - cluster.name=${CLUSTER_NAME} - cluster.initial_master_nodes=es01 - discovery.seed_hosts=es02 - - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} + - ELASTIC_PASSWORD=${ES_PASS} - bootstrap.memory_lock=true - xpack.security.enabled=true - xpack.security.http.ssl.enabled=true @@ -117,7 +117,7 @@ services: - cluster.name=${CLUSTER_NAME} - cluster.initial_master_nodes=es01,es02 - discovery.seed_hosts=es01 - - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} + - ELASTIC_PASSWORD=${ES_PASS} - bootstrap.memory_lock=true - xpack.security.enabled=true - xpack.security.http.ssl.enabled=true @@ -163,7 +163,7 @@ services: - cluster.name=${CLUSTER_NAME} - cluster.initial_master_nodes=es01,es03 - discovery.seed_hosts=es01 - - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} + - ELASTIC_PASSWORD=${ES_PASS} - bootstrap.memory_lock=true - xpack.security.enabled=true - xpack.security.http.ssl.enabled=true diff --git a/t/msc-actions.yaml b/t/msc-actions.yaml index 6ffbdab..f01fc25 100644 --- a/t/msc-actions.yaml +++ b/t/msc-actions.yaml @@ -26,12 +26,24 @@ actions: cluster_status: | [[.esctl]] cluster status | grep green + create_ilm: | + [[.esctl]] ilm create --hot-rollover-max-age 7d \ + --hot-rollover-max-primary-shard-size 25g \ + --warm-min-age 0 \ + --delete-min-age 14d [[.policy]] + + describe_ilm: | + [[.esctl]] ilm show [[.policy]] -t | grep -E "rollover when storage > 25g" + create_index_template: | [[.esctl]] index template create [[.index]] -i [[.index]] \ -s number_of_shards:3 \ -s index.sort.field:@timestamp \ - -r 1m \ + -r 1m --ilm-policy [[.policy]] \ user:keyword message:text @timestamp:date + + describe_index_template: | + [[.esctl]] index template show [[.index]] | grep -E "index.sort.field.*@timestamp" create_index: | [[.esctl]] index create -s 2 -r 2 [[.index]] @@ -57,7 +69,7 @@ actions: doc_add: | [[.esctl]] doc add -i [[.index]] '{"user": "[[.user]]", "message":"[[.message]]", "@timestamp":"[[.ts]]"}' - search: | + search_any: | [[.esctl]] search -i [[.index]] -l 1 | jq .source.message search_date: | @@ -66,3 +78,19 @@ actions: search_count: | [[.esctl]] search -i [[.index]] -l 5000 | wc -l | grep 1000 + search_content: | + [[.esctl]] search -i [[.index]] [[.content_pattern]] -l 1 | jq .source.message + + search_content_and: | + [[.esctl]] search -i [[.index]] [[.content_and_pattern]] -l 1 | jq .source.message + + nodes: | + [[.esctl]] node ls | grep es01 + + describe_node: | + [[.esctl]] node show [[.node]] | grep "Node version" + + license: | + [[.esctl]] license show | grep -E "Expires.*never" + + diff --git a/t/msc-cluster.yaml b/t/msc-cluster.yaml index 20e347d..0014a83 100644 --- a/t/msc-cluster.yaml +++ b/t/msc-cluster.yaml @@ -7,16 +7,30 @@ items: vars: index: test - + node: es01 + policy: testpolicy + tasks: - name: ls action: cluster_ls + + - name: license + action: license - name: status action: cluster_status + - name: ilm + action: create_ilm + + - name: check_ilm + action: describe_ilm + - name: template action: create_index_template + + - name: check_template + action: describe_index_template - name: index action: create_index @@ -26,3 +40,9 @@ tasks: - name: describe action: describe_index + + - name: nodes + action: nodes + + - name: check_node + action: describe_node diff --git a/t/msc-docs.yaml b/t/msc-docs.yaml index 8cf3c6f..bec980a 100644 --- a/t/msc-docs.yaml +++ b/t/msc-docs.yaml @@ -14,5 +14,8 @@ tasks: generate: user: $name - message: "$rand $rand $rand" + # will become something like: + # "content34 iBAXQ2Va Ko5gMwwu FEH2O99B" + # so we can search for "content3*" and get multiple matches + message: "content$int8 $rand make$int8 $rand" diff --git a/t/msc-search.yaml b/t/msc-search.yaml index c7835ea..4b24dbb 100644 --- a/t/msc-search.yaml +++ b/t/msc-search.yaml @@ -5,22 +5,27 @@ items: vars: index: test - time: 5s + time: 10s + content_pattern: "content3*" + content_and_pattern: "content3* make" tasks: - name: today action: date - - name: search - action: search + - name: search_any + action: search_any - name: date action: search_date args: today: today.result - - name: wait - action: wait - - name: count action: search_count + + - name: content + action: search_content + + - name: content_and + action: search_content_and