97 lines
4.5 KiB
Bash
97 lines
4.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -u -o pipefail
|
|
|
|
TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
source "${TEST_ROOT}/tests/testlib.sh"
|
|
source "${TEST_ROOT}/inc/deploy-pulse-lxc.sh"
|
|
|
|
assert_success "stable Pulse release" TAPM_PULSE_VALID_RELEASE v6.1.1
|
|
assert_success "prerelease Pulse release" TAPM_PULSE_VALID_RELEASE v6.2.0-rc.1
|
|
assert_failure "Pulse release requires v prefix" TAPM_PULSE_VALID_RELEASE 6.1.1
|
|
assert_failure "Pulse release rejects URL content" \
|
|
TAPM_PULSE_VALID_RELEASE 'v6.1.1/../../latest'
|
|
|
|
assert_equal amd64 "$(TAPM_PULSE_ARCH x86_64)" "x86 architecture mapping"
|
|
assert_equal arm64 "$(TAPM_PULSE_ARCH aarch64)" "ARM architecture mapping"
|
|
assert_failure "unsupported Pulse architecture" TAPM_PULSE_ARCH riscv64
|
|
|
|
test_bridge_selection_assignment() {
|
|
local bridge=''
|
|
|
|
TAPM_PULSE_SET_BRIDGE_FROM_SELECTION bridge 'bridge:vmbr0' || return 1
|
|
assert_equal vmbr0 "$bridge" "selected Pulse bridge assigned to caller"
|
|
}
|
|
|
|
assert_success "Pulse bridge selection assignment" test_bridge_selection_assignment
|
|
assert_failure "empty Pulse bridge selection rejected" \
|
|
TAPM_PULSE_SET_BRIDGE_FROM_SELECTION selected_bridge 'bridge:'
|
|
|
|
bootstrap_token='0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
bootstrap_output="║ Token: ${bootstrap_token} ║"
|
|
assert_equal "$bootstrap_token" \
|
|
"$(TAPM_PULSE_BOOTSTRAP_TOKEN_FROM_OUTPUT "$bootstrap_output")" \
|
|
"Pulse bootstrap token parsed"
|
|
assert_failure "malformed Pulse bootstrap output rejected" \
|
|
TAPM_PULSE_BOOTSTRAP_TOKEN_FROM_OUTPUT 'Token: not-a-token'
|
|
|
|
agent_token='0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
assert_equal "$agent_token" \
|
|
"$(TAPM_PULSE_TOKEN_FROM_RESPONSE "{\"token\":\"${agent_token}\"}")" \
|
|
"Pulse agent token parsed"
|
|
assert_failure "missing Pulse agent token rejected" \
|
|
TAPM_PULSE_TOKEN_FROM_RESPONSE '{"command":"install"}'
|
|
assert_failure "Pulse agent token containing whitespace rejected" \
|
|
TAPM_PULSE_TOKEN_FROM_RESPONSE '{"token":"invalid token"}'
|
|
assert_failure "non-hex Pulse agent token rejected" \
|
|
TAPM_PULSE_TOKEN_FROM_RESPONSE '{"token":"not-a-token"}'
|
|
|
|
nodes_json='[
|
|
{"node":"pve3","status":"offline"},
|
|
{"node":"pve2","status":"online"},
|
|
{"node":"pve1","status":"online"}
|
|
]'
|
|
assert_equal $'pve1\npve2' \
|
|
"$(TAPM_PULSE_ONLINE_NODES_FROM_JSON "$nodes_json")" \
|
|
"online Pulse nodes selected and sorted"
|
|
assert_equal 'pve3' \
|
|
"$(TAPM_PULSE_OFFLINE_NODES_FROM_JSON "$nodes_json")" \
|
|
"offline Pulse nodes reported"
|
|
|
|
assert_success "valid Pulse CTID" TAPM_PULSE_VALID_CTID 210
|
|
assert_failure "invalid Pulse CTID" TAPM_PULSE_VALID_CTID 99
|
|
assert_success "valid Pulse hostname" TAPM_PULSE_VALID_HOSTNAME pulse-monitor
|
|
assert_failure "invalid Pulse hostname" TAPM_PULSE_VALID_HOSTNAME 'pulse monitor'
|
|
assert_success "valid positive integer" TAPM_PULSE_VALID_POSITIVE_INTEGER 1024
|
|
assert_failure "zero is not positive" TAPM_PULSE_VALID_POSITIVE_INTEGER 0
|
|
assert_success "zero is a valid nonnegative integer" \
|
|
TAPM_PULSE_VALID_NONNEGATIVE_INTEGER 0
|
|
assert_failure "negative integer rejected" TAPM_PULSE_VALID_NONNEGATIVE_INTEGER -1
|
|
assert_success "valid Pulse port" TAPM_PULSE_VALID_PORT 7655
|
|
assert_failure "Pulse port too high" TAPM_PULSE_VALID_PORT 65536
|
|
assert_success "valid Pulse IPv4 CIDR" TAPM_PULSE_VALID_IPV4_CIDR 10.10.1.50/24
|
|
assert_failure "invalid Pulse IPv4 CIDR" TAPM_PULSE_VALID_IPV4_CIDR 10.10.1.500/24
|
|
assert_success "valid Pulse gateway" TAPM_PULSE_VALID_IPV4 10.10.0.1
|
|
assert_failure "gateway CIDR rejected" TAPM_PULSE_VALID_IPV4 10.10.0.1/16
|
|
assert_success "blank optional Pulse address accepted" \
|
|
TAPM_PULSE_VALID_OPTIONAL_IPV4_CIDR ''
|
|
assert_success "valid Pulse VLAN" TAPM_PULSE_VALID_OPTIONAL_VLAN 4094
|
|
assert_failure "Pulse VLAN zero rejected" TAPM_PULSE_VALID_OPTIONAL_VLAN 0
|
|
assert_success "blank Pulse VLAN accepted" TAPM_PULSE_VALID_OPTIONAL_VLAN ''
|
|
|
|
resources='[
|
|
{"type":"lxc","name":"pulse-a","tags":"tapm;pulse"},
|
|
{"type":"qemu","name":"unrelated"}
|
|
]'
|
|
assert_success "tagged Pulse LXC detected" TAPM_PULSE_RESOURCE_INSTALLED "$resources"
|
|
assert_success "legacy Pulse hostname detected" \
|
|
TAPM_PULSE_RESOURCE_INSTALLED '[{"type":"lxc","name":"Pulse"}]'
|
|
assert_failure "unrelated resource not detected" \
|
|
TAPM_PULSE_RESOURCE_INSTALLED '[{"type":"qemu","name":"pulse"}]'
|
|
|
|
ha_status=$'quorum OK\nmaster pve1 (active, Sat Jul 25 12:00:00 2026)\nlrm pve1 (active, Sat Jul 25 12:00:00 2026)'
|
|
assert_success "active Proxmox HA detected" TAPM_PULSE_HA_STATUS_ENABLED "$ha_status"
|
|
assert_failure "inactive Proxmox HA rejected" \
|
|
TAPM_PULSE_HA_STATUS_ENABLED $'quorum OK\nmaster pve1 (idle)'
|
|
|
|
finish_tests
|