#!/bin/bash
set -e

echo "Running maintainer tests for aiodns package"

# Use py3versions --supported as lintian expects
PYVERSIONS=$(py3versions --supported)

if [ -z "$PYVERSIONS" ]; then
    echo "No supported Python 3 versions found, using python3"
    PYVERSIONS="python3"
fi

for py in $PYVERSIONS; do
    echo "Testing with $py"

    # Test 1: Basic import
    $py -c "import aiodns; print('PASS: aiodns imports correctly with $py')"

    # Test 2: Resolver creation  
    $py -c "
import aiodns
resolver = aiodns.DNSResolver()
print('PASS: DNSResolver creation works with $py')
    "

    # Test 3: Error module
    $py -c "
import aiodns.error
print('PASS: Error module available with $py')
    "

    # Test 4: Basic attributes
    $py -c "
import aiodns
r = aiodns.DNSResolver()
assert hasattr(r, 'query'), 'Missing query method'
assert hasattr(r, 'gethostbyname'), 'Missing gethostbyname method'  
print('PASS: Basic API methods present with $py')
    "

    # Test 5: Basic functionality
    $py -c "
import asyncio
import aiodns

async def test_basic():
    resolver = aiodns.DNSResolver()
    assert hasattr(resolver, 'query')
    assert hasattr(resolver, 'gethostbyname')
    print('PASS: Basic functionality confirmed with $py')

asyncio.run(test_basic())
    "

    echo "All tests passed for $py"
    echo "---"
done

echo "All tests passed successfully for all Python versions"
