We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/sonicaj/tn_mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
run_middleware_tests.sh•4.84 kB
#!/bin/bash
# Script to run TrueNAS middleware unit tests using Docker
# Based on the GitHub Actions workflow
set -e
# Configuration
CONTAINER_NAME="truenas-middleware-test"
MIDDLEWARE_PATH="$1"
TEST_FILE="$2"
# Show usage
show_usage() {
echo "Usage: $0 <path_to_middleware_repo> [test_file]"
echo ""
echo "Parameters:"
echo " path_to_middleware_repo Path to middleware repository (required)"
echo " test_file Specific test file to run (optional, runs all tests if not provided)"
echo ""
echo "Examples:"
echo " $0 /path/to/middleware # Run all tests"
echo " $0 /path/to/middleware test_construct_schema.py # Run specific test"
}
# Validate parameters
if [ -z "$1" ]; then
echo "Error: Repository path is required"
show_usage
exit 1
fi
if [ ! -d "$MIDDLEWARE_PATH" ]; then
echo "Error: Middleware repository not found at $MIDDLEWARE_PATH"
show_usage
exit 1
fi
if [ ! -d "$MIDDLEWARE_PATH/src/middlewared" ]; then
echo "Error: src/middlewared directory not found in $MIDDLEWARE_PATH"
echo "Please ensure this is a valid middleware repository"
exit 1
fi
echo "Running middleware unit tests from: $MIDDLEWARE_PATH"
# Check if container exists
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Container '${CONTAINER_NAME}' already exists."
# Check if container is running
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Container is already running."
else
echo "Starting existing container..."
docker start "${CONTAINER_NAME}"
# Wait for container to be fully running
sleep 2
fi
else
echo "Creating new container '${CONTAINER_NAME}'..."
# Create and start container WITHOUT volume mounts
docker run -d \
--name "${CONTAINER_NAME}" \
--platform linux/amd64 \
ghcr.io/truenas/middleware:master \
tail -f /dev/null # Keep container running
echo "Container created. Running initial setup..."
# Run initial setup in the container
docker exec "${CONTAINER_NAME}" bash -c "
set -e
echo 'Installing development tools...'
# Install dev tools
/usr/bin/install-dev-tools
echo 'Development tools installed successfully!'
"
echo "Initial setup finished. Container is ready for testing."
fi
# Copy middleware code to container
echo "Copying middleware code to container..."
# Create workspace directory and remove existing middlewared if it exists
docker exec "${CONTAINER_NAME}" bash -c "mkdir -p /workspace && rm -rf /workspace/middlewared"
# Copy the middlewared directory to the container
echo "Copying $MIDDLEWARE_PATH/src/middlewared to container..."
docker cp "$MIDDLEWARE_PATH/src/middlewared" "${CONTAINER_NAME}:/workspace/middlewared"
# Build and install middleware
echo "Building and installing middleware..."
docker exec -w /workspace/middlewared "${CONTAINER_NAME}" bash -c "
set -e
echo 'Running make clean...'
make clean
echo 'Running make install...'
make install
echo 'Copying pytest files...'
cp -a /workspace/middlewared/middlewared/pytest /usr/local/lib/python3.11/dist-packages/middlewared/
echo 'Build and installation complete!'
"
# Determine what tests to run
if [ -n "$TEST_FILE" ]; then
echo "Searching for test file: $TEST_FILE"
# Search for the test file in the container
TEST_PATH=$(docker exec "${CONTAINER_NAME}" bash -c "
find /usr/local/lib/python3.11/dist-packages/middlewared/pytest -name '$TEST_FILE' -type f 2>/dev/null | head -1
")
if [ -z "$TEST_PATH" ]; then
echo "ERROR: Test file '$TEST_FILE' not found in the pytest directory"
echo "Available test files:"
docker exec "${CONTAINER_NAME}" bash -c "
find /usr/local/lib/python3.11/dist-packages/middlewared/pytest -name '*.py' -type f | grep -E 'test_.*\.py$' | sort
"
exit 1
fi
echo "Found test file at: $TEST_PATH"
TEST_COMMAND="pytest-3 -v --disable-pytest-warnings $TEST_PATH"
else
echo "Running all tests..."
TEST_COMMAND="pytest-3 -v --disable-pytest-warnings /usr/local/lib/python3.11/dist-packages/middlewared/pytest"
fi
# Run the tests
echo "========================================"
echo "Executing tests in container '${CONTAINER_NAME}'..."
echo "========================================"
docker exec -w /workspace/middlewared "${CONTAINER_NAME}" bash -c "
set -e
# Run the tests
echo 'Executing: $TEST_COMMAND'
$TEST_COMMAND
"
echo ""
echo "========================================"
echo "Tests have been executed successfully!"
echo "========================================"