Skip to content

Commit

Permalink
chore: support multiple test files for helm test (#255)
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <[email protected]>
  • Loading branch information
leninmehedy authored Aug 8, 2023
1 parent 5b17978 commit d25edfe
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
8 changes: 5 additions & 3 deletions charts/hedera-network/templates/configmaps/test-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
5 changes: 2 additions & 3 deletions charts/hedera-network/templates/tests/test-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions charts/hedera-network/tests/basic_deployment_test.sh
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit d25edfe

Please sign in to comment.