|
6 | 6 | import pytest |
7 | 7 |
|
8 | 8 | from gcsfs.extended_gcsfs import BucketType |
9 | | -from gcsfs.tests.settings import TEST_BUCKET |
| 9 | +from gcsfs.tests.settings import TEST_ZONAL_BUCKET |
10 | 10 |
|
11 | | -file_path = f"{TEST_BUCKET}/zonal-file-test" |
| 11 | +file_path = f"{TEST_ZONAL_BUCKET}/zonal-file-test" |
12 | 12 | test_data = b"hello world" |
13 | 13 |
|
14 | 14 | REQUIRED_ENV_VAR = "GCSFS_EXPERIMENTAL_ZB_HNS_SUPPORT" |
@@ -150,3 +150,38 @@ def test_zonal_file_not_implemented_methods( |
150 | 150 | method_to_call = getattr(f, method_name) |
151 | 151 | with pytest.raises(NotImplementedError): |
152 | 152 | method_to_call() |
| 153 | + |
| 154 | + |
| 155 | +@pytest.mark.skipif( |
| 156 | + os.environ.get("STORAGE_EMULATOR_HOST") != "https://storage.googleapis.com", |
| 157 | + reason="This test class is for real GCS only.", |
| 158 | +) |
| 159 | +class TestZonalFileRealGCS: |
| 160 | + """ |
| 161 | + Contains tests for ZonalFile write operations that run only against a |
| 162 | + real GCS backend. These tests validate end-to-end write behavior. |
| 163 | + """ |
| 164 | + |
| 165 | + def test_simple_upload_overwrite_behavior(self, extended_gcsfs): |
| 166 | + """Tests simple writes to a ZonalFile and verifies the content is overwritten""" |
| 167 | + with extended_gcsfs.open(file_path, "wb") as f: |
| 168 | + f.write(test_data) |
| 169 | + with extended_gcsfs.open(file_path, "wb", content_type="text/plain") as f: |
| 170 | + f.write(b"Sample text data.") |
| 171 | + assert extended_gcsfs.cat(file_path) == b"Sample text data." |
| 172 | + |
| 173 | + def test_large_upload(self, extended_gcsfs): |
| 174 | + """Tests writing a large chunk of data to a ZonalFile.""" |
| 175 | + large_data = b"a" * (5 * 1024 * 1024) # 5MB |
| 176 | + with extended_gcsfs.open(file_path, "wb") as f: |
| 177 | + f.write(large_data) |
| 178 | + assert extended_gcsfs.cat(file_path) == large_data |
| 179 | + |
| 180 | + def test_multiple_writes(self, extended_gcsfs): |
| 181 | + """Tests multiple write calls to the same ZonalFile handle.""" |
| 182 | + data1 = b"first part " |
| 183 | + data2 = b"second part" |
| 184 | + with extended_gcsfs.open(file_path, "wb") as f: |
| 185 | + f.write(data1) |
| 186 | + f.write(data2) |
| 187 | + assert extended_gcsfs.cat(file_path) == data1 + data2 |
0 commit comments