light-heart-labs--dreamserver
9e8f1bbeed
Dashboard / frontend (push) Failing after 0s
Dashboard / api (push) Failing after 0s
Lint PowerShell / powershell-lint (ubuntu-latest) (push) Failing after 1s
Python Lint / Lint Python with Ruff (push) Failing after 1s
ShellCheck / Lint shell scripts (push) Failing after 1s
Matrix Smoke / linux-smoke (push) Failing after 1s
Matrix Smoke / distro: cachyos (push) Failing after 15s
Matrix Smoke / distro: linux-mint-21.3 (push) Failing after 15s
Matrix Smoke / distro: debian-12 (push) Failing after 5m21s
Matrix Smoke / distro: fedora-41 (push) Failing after 4m56s
Matrix Smoke / distro: ubuntu-24.04 (push) Failing after 2m13s
Matrix Smoke / distro: rocky-9 (push) Failing after 10m39s
Matrix Smoke / distro: manjaro (push) Failing after 12m11s
Matrix Smoke / distro: opensuse-tw (push) Failing after 11m53s
Matrix Smoke / distro: archlinux (push) Failing after 20m3s
Matrix Smoke / distro: ubuntu-22.04 (push) Failing after 13m49s
Validate .env Schema / tier-1-env-validation (push) Successful in 52s
Validate .env Schema / tier-2-env-validation (push) Successful in 44s
Validate .env Schema / tier-3-env-validation (push) Successful in 52s
Validate .env Schema / tier-4-env-validation (push) Successful in 51s
Validate Extensions Catalog / Check catalog is up-to-date (push) Failing after 9m47s
Secret Scan / Scan for secrets (push) Failing after 21m4s
Validate Docker Compose / Validate Docker Compose files (push) Has been cancelled
Python Type Check / Type check with mypy (push) Has been cancelled
Validate .env Schema / tier-0-env-validation (push) Has been cancelled
Test Linux / integration-smoke (push) Has been cancelled
Lint PowerShell / powershell-lint (windows-latest) (push) Has been cancelled
Matrix Smoke / macos-smoke (push) Has been cancelled
129 行
4.2 KiB
Bash
129 行
4.2 KiB
Bash
#!/usr/bin/env bats
|
|
# ============================================================================
|
|
# BATS tests for installers/lib/logging.sh
|
|
# ============================================================================
|
|
# Tests: install_elapsed(), log(), success(), warn(), error()
|
|
|
|
load '../bats/bats-support/load'
|
|
load '../bats/bats-assert/load'
|
|
|
|
setup() {
|
|
# Define color vars as empty strings (no ANSI escape codes in test output)
|
|
export GRN=""
|
|
export BGRN=""
|
|
export AMB=""
|
|
export RED=""
|
|
export NC=""
|
|
|
|
# LOG_FILE as a temp file
|
|
export LOG_FILE="$BATS_TEST_TMPDIR/logging-test.log"
|
|
touch "$LOG_FILE"
|
|
|
|
# INSTALL_START_EPOCH set to a known value
|
|
export INSTALL_START_EPOCH=$(date +%s)
|
|
export INSTALL_NOW_EPOCH="$INSTALL_START_EPOCH"
|
|
|
|
# Source the library under test
|
|
source "$BATS_TEST_DIRNAME/../../installers/lib/logging.sh"
|
|
}
|
|
|
|
# ── install_elapsed ─────────────────────────────────────────────────────────
|
|
|
|
@test "install_elapsed: returns 0m 00s when just started" {
|
|
INSTALL_START_EPOCH=1700000000
|
|
INSTALL_NOW_EPOCH=1700000000
|
|
run install_elapsed
|
|
assert_success
|
|
assert_output "0m 00s"
|
|
}
|
|
|
|
@test "install_elapsed: returns correct elapsed time for 65 seconds" {
|
|
INSTALL_START_EPOCH=1700000000
|
|
INSTALL_NOW_EPOCH=1700000065
|
|
run install_elapsed
|
|
assert_success
|
|
assert_output "1m 05s"
|
|
}
|
|
|
|
@test "install_elapsed: returns correct elapsed time for 0 seconds" {
|
|
INSTALL_START_EPOCH=1700000000
|
|
INSTALL_NOW_EPOCH=1700000000
|
|
run install_elapsed
|
|
assert_success
|
|
assert_output "0m 00s"
|
|
}
|
|
|
|
@test "install_elapsed: returns correct elapsed time for 120 seconds" {
|
|
INSTALL_START_EPOCH=1700000000
|
|
INSTALL_NOW_EPOCH=1700000120
|
|
run install_elapsed
|
|
assert_success
|
|
assert_output "2m 00s"
|
|
}
|
|
|
|
# ── log ─────────────────────────────────────────────────────────────────────
|
|
|
|
@test "log: writes message to stdout" {
|
|
run log "test message"
|
|
assert_success
|
|
assert_output --partial "[INFO]"
|
|
assert_output --partial "test message"
|
|
}
|
|
|
|
@test "log: appends message to LOG_FILE" {
|
|
log "file message"
|
|
run cat "$LOG_FILE"
|
|
assert_output --partial "[INFO]"
|
|
assert_output --partial "file message"
|
|
}
|
|
|
|
# ── success ─────────────────────────────────────────────────────────────────
|
|
|
|
@test "success: writes message to stdout with OK tag" {
|
|
run success "all good"
|
|
assert_success
|
|
assert_output --partial "[OK]"
|
|
assert_output --partial "all good"
|
|
}
|
|
|
|
@test "success: appends message to LOG_FILE" {
|
|
success "all good"
|
|
run cat "$LOG_FILE"
|
|
assert_output --partial "[OK]"
|
|
assert_output --partial "all good"
|
|
}
|
|
|
|
# ── warn ────────────────────────────────────────────────────────────────────
|
|
|
|
@test "warn: writes message to stdout with WARN tag" {
|
|
run warn "be careful"
|
|
assert_success
|
|
assert_output --partial "[WARN]"
|
|
assert_output --partial "be careful"
|
|
}
|
|
|
|
@test "warn: appends message to LOG_FILE" {
|
|
warn "be careful"
|
|
run cat "$LOG_FILE"
|
|
assert_output --partial "[WARN]"
|
|
assert_output --partial "be careful"
|
|
}
|
|
|
|
# ── error ───────────────────────────────────────────────────────────────────
|
|
|
|
@test "error: writes to stderr and exits 1" {
|
|
run error "something broke"
|
|
assert_failure 1
|
|
assert_output --partial "[ERROR]"
|
|
assert_output --partial "something broke"
|
|
}
|
|
|
|
@test "error: appends message to LOG_FILE" {
|
|
# Run in subshell to catch exit
|
|
run error "crash now"
|
|
# Even though error exits, tee should have written before exiting
|
|
run cat "$LOG_FILE"
|
|
assert_output --partial "[ERROR]"
|
|
assert_output --partial "crash now"
|
|
}
|