From d25edfe70ad57f1c195a1bbee28a08bbe74f9d54 Mon Sep 17 00:00:00 2001 From: Lenin Mehedy Date: Tue, 8 Aug 2023 13:13:52 +1000 Subject: [PATCH] chore: support multiple test files for helm test (#255) Signed-off-by: Lenin Mehedy --- .../templates/configmaps/test-cm.yaml | 8 ++-- .../templates/tests/test-deployment.yaml | 5 +-- .../tests/basic_deployment_test.sh | 39 +++++++++++++++++++ .../{config-files/test.sh => tests/helper.sh} | 35 ++--------------- 4 files changed, 50 insertions(+), 37 deletions(-) create mode 100755 charts/hedera-network/tests/basic_deployment_test.sh rename charts/hedera-network/{config-files/test.sh => tests/helper.sh} (69%) diff --git a/charts/hedera-network/templates/configmaps/test-cm.yaml b/charts/hedera-network/templates/configmaps/test-cm.yaml index 36d0e6893..64407c40c 100644 --- a/charts/hedera-network/templates/configmaps/test-cm.yaml +++ b/charts/hedera-network/templates/configmaps/test-cm.yaml @@ -3,6 +3,8 @@ kind: ConfigMap metadata: name: test-cm data: - test.sh: | - {{- $total_nodes := len $.Values.hedera.nodes -}} - {{- tpl ($.Files.Get "config-files/test.sh") ( dict "total_nodes" $total_nodes "Template" $.Template ) | nindent 4 }} + {{- $total_nodes := len $.Values.hedera.nodes -}} + {{- range $path, $_ := .Files.Glob "tests/*.sh" }} + {{ base $path }}: | + {{- tpl ($.Files.Get $path) ( dict "total_nodes" $total_nodes "Template" $.Template ) | nindent 4 }} + {{- end }} diff --git a/charts/hedera-network/templates/tests/test-deployment.yaml b/charts/hedera-network/templates/tests/test-deployment.yaml index 2d7cdc7a4..487caf8e8 100644 --- a/charts/hedera-network/templates/tests/test-deployment.yaml +++ b/charts/hedera-network/templates/tests/test-deployment.yaml @@ -17,12 +17,11 @@ spec: - name: tester image: bitnami/kubectl:latest volumeMounts: - - mountPath: /scripts/test.sh + - mountPath: /tests name: test-volume - subPath: test.sh command: - "/bin/bash" - "-c" - - /scripts/test.sh + - /tests/basic_deployment_test.sh #- "while true;do echo sleeping; sleep 10;done" restartPolicy: Never diff --git a/charts/hedera-network/tests/basic_deployment_test.sh b/charts/hedera-network/tests/basic_deployment_test.sh new file mode 100755 index 000000000..07347a4c0 --- /dev/null +++ b/charts/hedera-network/tests/basic_deployment_test.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" +readonly SCRIPT_DIR + +# shellcheck source=./helper.sh +source "${SCRIPT_DIR}/helper.sh" + +function test_basic_deployment() { + local test_node_total_status + local test_systemctl_status + + test_node_total + local status="$?" + [ "${status}" = "${EX_OK}" ] && test_node_total_status="PASS" || test_node_total_status="FAIL" + + test_systemctl + local status="$?" + [ "${status}" = "${EX_OK}" ] && test_systemctl_status="PASS" || test_systemctl_status="FAIL" + + echo "-------------------------------------------------------------" + echo "Test results" + echo "-------------------------------------------------------------" + echo "test_node_total: ${test_node_total_status}" + echo "test_systemctl: ${test_systemctl_status}" + + [ "${test_node_total_status}" = "PASS" ] && \ + [ "${test_systemctl_status}" = "PASS" ] || return "${EX_ERR}" + + return "${EX_OK}" +} + +echo "Test scripts: " +echo "Test scripts: " +echo "==========================" +ls -la "${SCRIPT_DIR}"/ + +test_basic_deployment + diff --git a/charts/hedera-network/config-files/test.sh b/charts/hedera-network/tests/helper.sh similarity index 69% rename from charts/hedera-network/config-files/test.sh rename to charts/hedera-network/tests/helper.sh index b867a535a..7aafd0c14 100755 --- a/charts/hedera-network/config-files/test.sh +++ b/charts/hedera-network/tests/helper.sh @@ -1,9 +1,9 @@ #!/bin/bash -EX_OK=0 -EX_ERR=1 +readonly EX_OK=0 +readonly EX_ERR=1 -TOTAL_NODES="{{ .total_nodes }}" +readonly TOTAL_NODES="{{ .total_nodes }}" function get_pod_list() { local pattern=$1 @@ -24,7 +24,7 @@ function test_node_total() { echo "Nodes: " "${nodes[@]}" local node_total=${#nodes[@]} - echo "Total network node: ${node_total} (expected: ${TOTAL_NODES})" + echo "Total network node: ${node_total} (expected - ${TOTAL_NODES})" echo "" # assert true @@ -72,30 +72,3 @@ function test_systemctl() { return "${EX_OK}" } - -function run_tests() { - local test_node_total_status - local test_systemctl_status - - test_node_total - local status="$?" - [ "${status}" = "${EX_OK}" ] && test_node_total_status="PASS" || test_node_total_status="FAIL" - - test_systemctl - local status="$?" - [ "${status}" = "${EX_OK}" ] && test_systemctl_status="PASS" || test_systemctl_status="FAIL" - - echo "-------------------------------------------------------------" - echo "Test results" - echo "-------------------------------------------------------------" - echo "test_node_total: ${test_node_total_status}" - echo "test_systemctl: ${test_systemctl_status}" - - [ "${test_node_total_status}" = "PASS" ] && \ - [ "${test_systemctl_status}" = "PASS" ] || return "${EX_ERR}" - - return "${EX_OK}" -} - -run_tests -