dharma/scripts/test_testsite.sh
Felipe M. 0ef15167d5
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
initial release
2025-05-04 10:49:50 +02:00

74 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
set -e
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}Dharma Testsite Test Runner${NC}"
echo -e "${BLUE}---------------------------${NC}"
echo
# Ensure we're in the project root
cd "$(dirname "$0")/.."
# Build dharma binary for testing
echo -e "${BLUE}Building dharma binary...${NC}"
go build -o dharma_test ./cmd/dharma
# Make the script executable
chmod +x ./dharma_test
# Start a simple HTTP server for the testsite
echo -e "${BLUE}Starting testsite server...${NC}"
cd testsite
SERVER_PID=""
# Function to clean up server and binary
cleanup() {
echo -e "${BLUE}Cleaning up...${NC}"
if [ ! -z "$SERVER_PID" ]; then
echo "Stopping server (PID: $SERVER_PID)..."
kill $SERVER_PID 2>/dev/null || true
fi
cd ..
[ -f ./dharma_test ] && rm ./dharma_test
echo -e "${GREEN}Cleanup complete.${NC}"
}
# Set up cleanup on script exit
trap cleanup EXIT
# Start the server in the background
python3 -m http.server 8765 &
SERVER_PID=$!
echo -e "${GREEN}Testsite server started on http://localhost:8765${NC}"
echo
sleep 1
cd ..
# Run dharma against the testsite
echo -e "${BLUE}Running dharma against testsite...${NC}"
./dharma_test http://localhost:8765
echo
echo -e "${BLUE}Testing different output formats...${NC}"
echo -e "${BLUE}JSON format:${NC}"
./dharma_test --format json http://localhost:8765 | head -n 10
echo "..."
echo -e "${BLUE}CSV format:${NC}"
./dharma_test --format csv http://localhost:8765 | head -n 5
echo "..."
echo -e "${BLUE}Internal links only:${NC}"
./dharma_test --internal-only http://localhost:8765 | grep -m 3 "found.html"
echo "..."
echo
echo -e "${GREEN}All tests completed successfully!${NC}"