#!/bin/bash set -e # CONTRACT: GOMAXPROCS=1 (Frugality Manifesto) COVERAGE_THRESHOLD=60 REPO_ROOT=$(git rev-parse --show-toplevel) BACKEND_DIR="$REPO_ROOT/veza-backend-api" echo "Backend Unit Tests (Low Power Mode)" cd "$BACKEND_DIR" export GOMAXPROCS=1 echo "Constraint: GOMAXPROCS=1" echo "Running Unit Tests with coverage..." go test ./internal/handlers/... ./internal/services/... -short -coverprofile=coverage.out -covermode=atomic COVERAGE=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | tr -d '%') echo "Coverage: ${COVERAGE}%" if awk -v c="$COVERAGE" -v t="$COVERAGE_THRESHOLD" 'BEGIN {exit !(c+0>=t)}'; then echo "Coverage gate passed (>= ${COVERAGE_THRESHOLD}%)" else echo "FATAL: Coverage ${COVERAGE}% is below threshold ${COVERAGE_THRESHOLD}%" exit 1 fi echo "Unit tests passed."