#!/usr/bin/env bash # test.sh - Script to test the tsysdevstack-toolboxes-docs container set -e # Default values IMAGE_NAME="tsysdevstack/toolboxes-docs" TAG="latest" CONTAINER_NAME="test-tsysdevstack-toolboxes-docs" TEST_DIR="/tmp/test-tsysdevstack-toolboxes-docs" # Function to print test results print_result() { if [ $? -eq 0 ]; then echo "✅ PASS: $1" else echo "❌ FAIL: $1" exit 1 fi } # Function to run a command in the container and check the result run_test_command() { local test_name="$1" local command="$2" echo "Running test: $test_name" docker run --rm --name "$CONTAINER_NAME-$(date +%s)" "$IMAGE_NAME:$TAG" bash -c "$command" print_result "$test_name" } # Function to test if a command exists in the container test_command_exists() { local test_name="$1" local command="$2" run_test_command "$test_name" "which $command" } # Function to test if a specific version of a tool is available test_version_command() { local test_name="$1" local command="$2" local expected_version="$3" echo "Running version test: $test_name" docker run --rm --name "$CONTAINER_NAME-$(date +%s)" "$IMAGE_NAME:$TAG" bash -c "$command" | grep "$expected_version" > /dev/null print_result "$test_name" } # Main test execution main() { echo "Starting tests for $IMAGE_NAME:$TAG..." # Test that core utilities exist test_command_exists "Check if pandoc exists" "pandoc" test_command_exists "Check if mdbook exists" "mdbook" test_command_exists "Check if typst exists" "typst" test_command_exists "Check if marp exists" "marp" test_command_exists "Check if markwhen exists" "markwhen" test_command_exists "Check if quarto exists" "quarto" test_command_exists "Check if jq exists" "jq" test_command_exists "Check if yq exists" "yq" test_command_exists "Check if wkhtmltopdf exists" "wkhtmltopdf" test_command_exists "Check if bibtool exists" "bibtool" test_command_exists "Check if vale exists" "vale" test_command_exists "Check if kroki exists" "kroki" test_command_exists "Check if fish shell exists" "fish" test_command_exists "Check if zsh exists" "zsh" test_command_exists "Check if bash exists" "bash" # Test that TeXLive is properly installed test_command_exists "Check if xelatex exists" "xelatex" test_command_exists "Check if pdflatex exists" "pdflatex" # Test that Python and Node.js are managed by mise run_test_command "Check if Python is available via mise" "python --version" run_test_command "Check if Node.js is available via mise" "node --version" # Test that we can run a simple pandoc command run_test_command "Test basic pandoc functionality" "echo '# Test' | pandoc -f markdown -t html | grep '

Test

'" # Test that we can run a simple mdbook command run_test_command "Test basic mdbook functionality" "mdbook --version" # Test that we can run a simple typst command run_test_command "Test basic typst functionality" "echo '# Hello' > /tmp/test.typ && typst compile /tmp/test.typ /tmp/test.pdf && [ -f /tmp/test.pdf ]" # Test that user is not root run_test_command "Check that default user is not root" "whoami | grep tsysdevstack" # Test that required directories exist run_test_command "Check that output directory exists" "[ -d /home/tsysdevstack/TSYSDevStack/Toolbox/docs/output ]" # Test that we can write to the output directory run_test_command "Test write access to output directory" "touch /home/tsysdevstack/TSYSDevStack/Toolbox/docs/output/test_file.txt && [ -f /home/tsysdevstack/TSYSDevStack/Toolbox/docs/output/test_file.txt ]" echo "All tests passed! 🎉" } main