#!/bin/bash

echo "🔍 Testing Enhanced Container Scanner Features"
echo "=============================================="

# Test image versioning analysis
echo -e "\n1. Testing Image Versioning Analysis:"
echo "   - bitnami/mysql:latest (should be CRITICAL)"
echo "   - bitnami/mysql:8.0.35 (should be pinned)"
echo "   - bitnami/redis:7.2.4 (should be semver)"

# Test Helm detection
echo -e "\n2. Testing Helm Detection:"
if command -v helm &> /dev/null; then
    echo "   ✅ Helm CLI available"
    helm list --all-namespaces 2>/dev/null || echo "   📋 No Helm releases found"
else
    echo "   ⚠️  Helm CLI not available - will use kubectl detection"
fi

# Test kubectl availability
echo -e "\n3. Testing Kubernetes Access:"
if command -v kubectl &> /dev/null; then
    echo "   ✅ kubectl available"
    kubectl cluster-info --request-timeout=5s 2>/dev/null && echo "   ✅ Cluster accessible" || echo "   ⚠️  No cluster access"
else
    echo "   ❌ kubectl not available"
fi

# Test container security analysis
echo -e "\n4. Testing Container Security Analysis:"
if kubectl get deployments --all-namespaces -o json 2>/dev/null | grep -q "securityContext"; then
    echo "   ✅ Security contexts detected"
else
    echo "   📋 No security contexts found"
fi

if kubectl get deployments --all-namespaces -o json 2>/dev/null | grep -q "resources"; then
    echo "   ✅ Resource limits detected"
else
    echo "   📋 No resource limits found"
fi

# Test Bitnami image detection
echo -e "\n5. Testing Bitnami Image Detection:"
if kubectl get pods --all-namespaces -o jsonpath='{.items[*].spec.containers[*].image}' 2>/dev/null | grep -q "bitnami"; then
    echo "   ✅ Bitnami images detected"
else
    echo "   📋 No Bitnami images found"
fi
done

echo -e "\n6. Sample Enhanced Analysis Commands:"
echo "   # Analyze specific image:"
echo "   cis enhanced --image bitnami/mysql:latest"
echo ""
echo "   # Analyze namespace:"
echo "   cis enhanced --namespace production"
echo ""
echo "   # Analyze from scan results:"
echo "   cis enhanced --input scan-results.json"
echo ""
echo "   # JSON output:"
echo "   cis enhanced --image bitnami/redis:7.2.4 --output json"

echo -e "\n✅ Enhanced features test completed!"
