#!/usr/bin/env bash # Script to test the tsysdevstack-toolboxes-docs container set -e # Default values IMAGE_NAME="tsysdevstack/toolbox-docs:latest" CONTAINER_NAME="tsysdevstack-toolboxes-docs-test" WORKDIR="/home/tsysdevstack/docs" echo "Starting tests for tsysdevstack-toolboxes-docs container..." # Function to run a command in the container and check the exit code run_test() { local test_name="$1" local command="$2" local expected_result="${3:-0}" # Default expected result is 0 (success) echo "Running test: $test_name" echo "Command: $command" # Run the command in the container if docker run --rm --name "${CONTAINER_NAME}-$(date +%s%N)" "$IMAGE_NAME" bash -c "$command"; then if [ "$expected_result" -eq 0 ]; then echo "✓ PASS: $test_name" else echo "✗ FAIL: $test_name - Expected failure but command succeeded" return 1 fi else if [ "$expected_result" -ne 0 ]; then echo "✓ PASS: $test_name - Command failed as expected" else echo "✗ FAIL: $test_name - Command failed unexpectedly" return 1 fi fi echo "" } # Test 1: Check if user is tsysdevstack run_test "User verification" "whoami | grep tsysdevstack" # Test 2: Check if required tools are installed run_test "Pandoc installation" "pandoc --version" run_test "MdBook installation" "mdbook --version" run_test "Typst installation" "typst --version" run_test "Marp CLI installation" "marp --version" run_test "Quarto installation" "quarto --version" run_test "YQ installation" "yq --version" run_test "JQ installation" "jq --version" run_test "Vale installation" "vale --version" run_test "BibTool installation" "bibtool -h" run_test "Wkhtmltopdf installation" "wkhtmltopdf --version" run_test "Joplin installation" "npm list -g joplin || echo 'joplin not found via npm'" # Test 3: Check if Python is available via mise run_test "Python via mise" "mise exec -- python --version" # Test 4: Check if Node.js is available via mise run_test "Node.js via mise" "mise exec -- node --version" # Test 5: Check if Rust is available via mise run_test "Rust via mise" "mise exec -- rustc --version" # Test 6: Check if Ruby is available via mise run_test "Ruby via mise" "mise exec -- ruby --version" # Test 7: Check if TeXLive is properly installed run_test "TeXLive installation" "pdflatex --version" # Test 8: Check if Git is available run_test "Git installation" "git --version" # Test 9: Check if shells are available run_test "Fish shell installation" "fish --version" run_test "Zsh installation" "zsh --version" run_test "Bash installation" "bash --version" # Test 10: Check if Mise is working properly run_test "Mise activation" "source ~/.bashrc && mise --version" # Test 11: Test basic functionality - convert markdown to PDF with Pandoc echo "Running advanced test: Pandoc markdown to PDF conversion" cat << 'EOF' > /tmp/test.md % Test Document % Test Author # Introduction This is a test document to verify that Pandoc is working correctly. ## Features - Pandoc conversion - Markdown formatting - PDF generation ### Code Block Example ```python def hello(): print("Hello, World!") ``` EOF # Run a simple conversion test inside the container if docker run --rm -v /tmp:/tmp -w /tmp "$IMAGE_NAME" bash -c "pandoc test.md -o test.pdf"; then echo "✓ PASS: Pandoc conversion test" # Clean up the generated file rm -f /tmp/test.pdf else echo "✗ FAIL: Pandoc conversion test" exit 1 fi echo "" # Test 12: Check if the working directory exists run_test "Working directory exists" "test -d $WORKDIR" echo "All tests completed successfully!"