#!/bin/bash # Test functions for machine setup scripts # Safe testing without system modifications set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Source shared library functions source "$SCRIPT_DIR/lib.sh" test_sheet_numbers() { echo "Testing sheet number generation..." # Test cases with expected sheet numbers local tests=( "topsheet:5" # Default tinsnip sheet ) for test_case in "${tests[@]}"; do IFS=':' read -r sheet expected <<< "$test_case" actual=$(get_sheet_number "$sheet") if [[ "$actual" == "$expected" ]]; then echo "✓ $sheet = $actual" else echo "✗ $sheet = $actual (expected $expected)" fi done } test_uid_calculation() { echo "Testing UID calculation..." # Test cases for default sheet (topsheet) - only station which doesn't require registry local tests=( "station:prod:50000" # topsheet sheet (S=5), S=00 "station:test:50010" # topsheet sheet (S=5), S=00 ) for test_case in "${tests[@]}"; do IFS=':' read -r service env expected <<< "$test_case" actual=$(calculate_service_uid "$service" "$env") if [[ "$actual" == "$expected" ]]; then echo "✓ $service:$env = $actual" else echo "✗ $service:$env = $actual (expected $expected)" fi done unset TIN_SHEET } test_nfs_path_generation() { echo "Testing NFS path generation..." local sheet="topsheet" # Default for testing local tests=( "station:prod:/volume1/tinsnip/${sheet}/station/prod" "gazette:test:/volume1/tinsnip/${sheet}/gazette/test" ) for test_case in "${tests[@]}"; do IFS=':' read -r service env expected <<< "$test_case" actual="/volume1/tinsnip/${sheet}/${service}/${env}" if [[ "$actual" == "$expected" ]]; then echo "✓ $service:$env = $actual" else echo "✗ $service:$env = $actual (expected $expected)" fi done } test_xdg_paths() { echo "Testing XDG path generation..." export XDG_STATE_HOME="$HOME/.local/state" export XDG_DATA_HOME="$HOME/.local/share" export XDG_CONFIG_HOME="$HOME/.config" local service="gazette" local sheet="${TIN_SHEET:-topsheet}" # Use env var or default echo "XDG paths for $service:" echo " State: ${XDG_STATE_HOME}/${sheet}/@${service}" echo " Data: ${XDG_DATA_HOME}/${sheet}/@${service}" echo " Config: ${XDG_CONFIG_HOME}/${sheet}/@${service}" } calculate_service_ports() { local service_uid="$1" local port_count="${2:-3}" for ((i=0; i