Skip to content

Commit f5a91bd

Browse files
authored
Merge pull request xencon#1452 from sbadakhc/issue-1417/stack-unit-tests
Add stack helper unit tests (xencon#1417)
2 parents 8c1f12f + cf1d52c commit f5a91bd

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
# Test 03: internal stack.sh helper functions
3+
# No running stack required -- tests pure helper functions only
4+
5+
set -e
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
8+
# shellcheck source=/dev/null
9+
source "${SCRIPT_DIR}/lib/core/common.sh"
10+
# shellcheck source=/dev/null
11+
source "${SCRIPT_DIR}/lib/cli/profile.sh"
12+
# shellcheck source=/dev/null
13+
source "${SCRIPT_DIR}/lib/aixcl/commands/stack.sh"
14+
# shellcheck source=/dev/null
15+
source "${SCRIPT_DIR}/tests/lib/test-framework.sh"
16+
17+
log_test_start "test-03-stack-helpers"
18+
19+
# ---------------------------------------------------------------------------
20+
# _print_stopped_status
21+
# ---------------------------------------------------------------------------
22+
23+
bld_output="$(_print_stopped_status bld)"
24+
assert_string_contains "$bld_output" "AIXCL Stack Stopped" \
25+
"_print_stopped_status outputs header"
26+
assert_string_contains "$bld_output" "Profile: bld" \
27+
"_print_stopped_status includes profile name"
28+
assert_string_contains "$bld_output" "vault" \
29+
"_print_stopped_status bld includes vault"
30+
assert_string_contains "$bld_output" "postgres" \
31+
"_print_stopped_status bld includes postgres"
32+
assert_string_not_contains "$bld_output" "open-webui" \
33+
"_print_stopped_status bld excludes open-webui"
34+
assert_string_not_contains "$bld_output" "pgadmin" \
35+
"_print_stopped_status bld excludes pgadmin"
36+
37+
sys_output="$(_print_stopped_status sys)"
38+
assert_string_contains "$sys_output" "Profile: sys" \
39+
"_print_stopped_status sys includes profile name"
40+
assert_string_contains "$sys_output" "open-webui" \
41+
"_print_stopped_status sys includes open-webui"
42+
assert_string_contains "$sys_output" "pgadmin" \
43+
"_print_stopped_status sys includes pgadmin"
44+
45+
# ---------------------------------------------------------------------------
46+
# _load_vault_token_for_stack -- env var shortcut (no GPG, no file I/O)
47+
# ---------------------------------------------------------------------------
48+
49+
VAULT_TOKEN="test-token-abc123"
50+
export VAULT_TOKEN
51+
52+
set +e
53+
token_output="$(_load_vault_token_for_stack 2>&1)"
54+
token_exit=$?
55+
set -e
56+
57+
assert_string_contains "$token_output" "VAULT_TOKEN" \
58+
"_load_vault_token_for_stack uses env var when set"
59+
[ "$token_exit" -eq 0 ] \
60+
&& log_success "_load_vault_token_for_stack env var path returns 0" \
61+
|| { log_error "_load_vault_token_for_stack env var path returned non-zero ($token_exit)"; false; }
62+
63+
unset VAULT_TOKEN
64+
65+
# ---------------------------------------------------------------------------
66+
# _load_vault_token_for_stack -- missing token file returns error
67+
# Use a temp SCRIPT_DIR so the real .security/vault-root-token.gpg is not used.
68+
# ---------------------------------------------------------------------------
69+
70+
_tmp_dir="$(mktemp -d)"
71+
_real_script_dir="$SCRIPT_DIR"
72+
SCRIPT_DIR="$_tmp_dir"
73+
74+
set +e
75+
missing_output="$(_load_vault_token_for_stack 2>&1)"
76+
missing_exit=$?
77+
set -e
78+
79+
SCRIPT_DIR="$_real_script_dir"
80+
rm -rf "$_tmp_dir"
81+
82+
assert_string_contains "$missing_output" "Error" \
83+
"_load_vault_token_for_stack missing file outputs error"
84+
[ "$missing_exit" -ne 0 ] \
85+
&& log_success "_load_vault_token_for_stack missing file returns non-zero" \
86+
|| { log_error "_load_vault_token_for_stack missing file should return non-zero"; false; }
87+
88+
log_test_pass "Stack helper functions work correctly"

0 commit comments

Comments
 (0)