"""
Tests for cert_trust.bootstrap module
"""
import os
import sys
from unittest.mock import patch, MagicMock

import pytest


class TestBootstrap:
    """Test bootstrap module behavior."""
    
    def test_bootstrap_imports_without_error(self):
        """Bootstrap should import successfully."""
        # Import should not raise
        import cert_trust.bootstrap
    
    def test_bootstrap_respects_disabled_env_var(self):
        """Bootstrap should exit early if CERT_TRUST_DISABLED is set."""
        with patch.dict(os.environ, {"CERT_TRUST_DISABLED": "1"}):
            # Re-import to trigger the env check
            import importlib
            import cert_trust.bootstrap
            importlib.reload(cert_trust.bootstrap)
            # If it doesn't raise, it worked
    
    @patch('cert_trust.bootstrap.truststore', create=True)
    def test_bootstrap_uses_truststore_if_available(self, mock_truststore):
        """Bootstrap should use truststore if available."""
        mock_inject = MagicMock()
        mock_truststore.inject_into_ssl = mock_inject
        
        # Re-import to trigger logic
        import importlib
        import cert_trust.bootstrap
        importlib.reload(cert_trust.bootstrap)
        
        # Check if inject was called (may not be in test environment)
        # This is a best-effort test


if __name__ == "__main__":
    pytest.main([__file__, "-v"])
