|
| 1 | +import zipfile |
| 2 | + |
1 | 3 | from pathlib import Path |
2 | 4 |
|
3 | 5 | import pytest |
@@ -77,3 +79,50 @@ def test_factory_raises_value_error_for_invalid_file(tmp_path: Path) -> None: |
77 | 79 |
|
78 | 80 | with pytest.raises(ValueError, match="Input is not a supported artifact"): |
79 | 81 | ArtifactFactory.from_path(invalid_file) |
| 82 | + |
| 83 | + |
| 84 | +def test_factory_rejects_empty_zip(tmp_path: Path) -> None: |
| 85 | + """Test that factory rejects completely empty zip files.""" |
| 86 | + empty_zip = tmp_path / "empty.zip" |
| 87 | + with zipfile.ZipFile(empty_zip, "w"): |
| 88 | + pass # Create empty zip |
| 89 | + |
| 90 | + with pytest.raises(ValueError, match="Input is not a supported artifact"): |
| 91 | + ArtifactFactory.from_path(empty_zip) |
| 92 | + |
| 93 | + |
| 94 | +def test_factory_rejects_zip_with_only_empty_folders(tmp_path: Path) -> None: |
| 95 | + """Test that factory rejects zip files with only empty directories.""" |
| 96 | + zip_with_folders = tmp_path / "empty_folders.zip" |
| 97 | + with zipfile.ZipFile(zip_with_folders, "w") as zf: |
| 98 | + # Add empty directories |
| 99 | + zf.writestr("Products/", "") |
| 100 | + zf.writestr("Applications/", "") |
| 101 | + zf.writestr("dSYMs/", "") |
| 102 | + |
| 103 | + with pytest.raises(ValueError, match="Input is not a supported artifact"): |
| 104 | + ArtifactFactory.from_path(zip_with_folders) |
| 105 | + |
| 106 | + |
| 107 | +def test_factory_rejects_xcarchive_missing_info_plist(tmp_path: Path) -> None: |
| 108 | + """Test that factory rejects XCArchive-like structure missing Info.plist.""" |
| 109 | + malformed_xcarchive = tmp_path / "no_info_plist.zip" |
| 110 | + with zipfile.ZipFile(malformed_xcarchive, "w") as zf: |
| 111 | + # Has Products/Applications structure but missing Info.plist |
| 112 | + zf.writestr("Products/Applications/MyApp.app/MyApp", "fake binary") |
| 113 | + zf.writestr("Products/Applications/MyApp.app/some_file.txt", "content") |
| 114 | + |
| 115 | + with pytest.raises(ValueError, match="Input is not a supported artifact"): |
| 116 | + ArtifactFactory.from_path(malformed_xcarchive) |
| 117 | + |
| 118 | + |
| 119 | +def test_factory_rejects_xcarchive_missing_products_structure(tmp_path: Path) -> None: |
| 120 | + """Test that factory rejects zip with Info.plist but no Products/Applications structure.""" |
| 121 | + malformed_xcarchive = tmp_path / "no_products.zip" |
| 122 | + with zipfile.ZipFile(malformed_xcarchive, "w") as zf: |
| 123 | + # Has Info.plist but wrong structure |
| 124 | + zf.writestr("Info.plist", "<?xml version='1.0'?><plist></plist>") |
| 125 | + zf.writestr("SomeOtherFolder/MyApp.app/MyApp", "fake binary") |
| 126 | + |
| 127 | + with pytest.raises(ValueError, match="Input is not a supported artifact"): |
| 128 | + ArtifactFactory.from_path(malformed_xcarchive) |
0 commit comments