#!/bin/bash

# Directory containing the test scripts
test_dir="/usr/libexec/testtools"

# Get all test-XXX files from the directory
test_files=$(ls $test_dir/test-* 2> /dev/null)

# Check if any test files were found
if [ -z "$test_files" ]; then
    echo "No test scripts found."
    exit 1
fi

echo "Available tests:"
select fname in $(echo $test_files | xargs -n 1 basename | sed 's/test-//'); do
    test_script="test-$fname"
    create_script="create-test-$fname"

    # Check if the selected test has a corresponding create script
    if [ -f "$test_dir/$create_script" ]; then
        echo "Running $create_script..."
        sudo $test_dir/$create_script
    else
        echo "No create script found for $fname"
    fi

    # Update the active test link
    sudo ln -sfn $test_dir/$test_script /usr/libexec/testtools/active-test
    echo "Activated $test_script as the current test."

    break  # Exit the select loop after one choice
done

