|
10 | 10 | import os |
11 | 11 | import platform |
12 | 12 | import subprocess |
| 13 | +import tempfile |
13 | 14 | import unittest |
14 | 15 | from pathlib import Path |
15 | 16 | from unittest.mock import MagicMock, Mock, mock_open, patch |
@@ -221,5 +222,69 @@ def test_repo_update_success(self, mock_ensure_helm, mock_mkdir, mock_run): |
221 | 222 | self.assertIn("update", call_args) |
222 | 223 |
|
223 | 224 |
|
| 225 | +class TestHelmManagerRealDownload(unittest.TestCase): |
| 226 | + """Integration tests for HelmManager that perform real downloads.""" |
| 227 | + |
| 228 | + def setUp(self): |
| 229 | + """Set up test fixtures.""" |
| 230 | + self.test_helm_version = "3.14.0" |
| 231 | + self.temp_dir = None |
| 232 | + |
| 233 | + def tearDown(self): |
| 234 | + """Clean up test fixtures.""" |
| 235 | + if self.temp_dir and os.path.exists(self.temp_dir): |
| 236 | + import shutil |
| 237 | + shutil.rmtree(self.temp_dir, ignore_errors=True) |
| 238 | + |
| 239 | + @unittest.skipIf(os.environ.get('SKIP_INTEGRATION_TESTS'), "Skipping integration test") |
| 240 | + def test_real_download_all_platforms(self): |
| 241 | + """Test real helm binary download for all supported OS and architecture combinations.""" |
| 242 | + import shutil |
| 243 | + |
| 244 | + platforms = [ |
| 245 | + ("linux", "amd64"), |
| 246 | + ("linux", "arm64"), |
| 247 | + ("linux", "arm"), |
| 248 | + ("linux", "386"), |
| 249 | + ("darwin", "amd64"), |
| 250 | + ("darwin", "arm64"), |
| 251 | + ("windows", "amd64"), |
| 252 | + # ("windows", "arm64"), # The blob does not exist for this platform |
| 253 | + ] |
| 254 | + |
| 255 | + for os_name, arch in platforms: |
| 256 | + with self.subTest(os=os_name, arch=arch): |
| 257 | + # Create fresh temp directory for each platform |
| 258 | + if self.temp_dir and os.path.exists(self.temp_dir): |
| 259 | + shutil.rmtree(self.temp_dir, ignore_errors=True) |
| 260 | + |
| 261 | + self.temp_dir = tempfile.mkdtemp() |
| 262 | + |
| 263 | + try: |
| 264 | + with patch('azext_aks_agent.agent.k8s.helm_manager.HelmManager._get_platform_info') as mock_platform: |
| 265 | + mock_platform.return_value = (os_name, arch) |
| 266 | + |
| 267 | + manager = HelmManager.__new__(HelmManager) |
| 268 | + manager.local_bin_dir = Path(self.temp_dir) |
| 269 | + manager.helm_version = self.test_helm_version |
| 270 | + |
| 271 | + # Perform actual download |
| 272 | + result = manager._download_helm_binary() |
| 273 | + |
| 274 | + # Verify no exception was raised and binary exists |
| 275 | + self.assertIsNotNone(result, f"Download failed for {os_name}-{arch}") |
| 276 | + self.assertTrue(os.path.exists(result), f"Binary not found for {os_name}-{arch}") |
| 277 | + self.assertIn("helm", result) |
| 278 | + |
| 279 | + # Verify binary is executable on Unix systems |
| 280 | + if os_name != "windows": |
| 281 | + self.assertTrue(os.access(result, os.X_OK), f"Binary not executable for {os_name}-{arch}") |
| 282 | + finally: |
| 283 | + # Clean up temp directory after each platform test |
| 284 | + if self.temp_dir and os.path.exists(self.temp_dir): |
| 285 | + shutil.rmtree(self.temp_dir, ignore_errors=True) |
| 286 | + self.temp_dir = None |
| 287 | + |
| 288 | + |
224 | 289 | if __name__ == '__main__': |
225 | 290 | unittest.main() |
0 commit comments