|
21 | 21 | import tempfile |
22 | 22 | import threading |
23 | 23 | import uuid |
| 24 | +from datetime import datetime |
24 | 25 | from typing import Any |
25 | 26 | from unittest import mock |
26 | 27 |
|
|
32 | 33 | from botocore.credentials import Credentials |
33 | 34 | from fsspec.implementations.local import LocalFileSystem |
34 | 35 | from fsspec.spec import AbstractFileSystem |
| 36 | +from google.oauth2.credentials import Credentials as GoogleCredentials |
35 | 37 | from requests_mock import Mocker |
36 | 38 |
|
37 | 39 | from pyiceberg.catalog.rest import _user_agent |
@@ -763,6 +765,29 @@ def test_adls_account_name_not_overridden_when_in_properties() -> None: |
763 | 765 | ) |
764 | 766 |
|
765 | 767 |
|
| 768 | +def test_fsspec_gcs_token_with_expiry() -> None: |
| 769 | + """Test that a GCS token with an expiry is passed to gcsfs as google-auth credentials.""" |
| 770 | + properties: Properties = {"gcs.oauth2.token": "token", "gcs.oauth2.token-expires-at": "1700000000000"} |
| 771 | + |
| 772 | + with mock.patch("gcsfs.GCSFileSystem") as mock_gcsfs: |
| 773 | + FsspecFileIO(properties=properties).new_input(location="gs://bucket/path/file.parquet") |
| 774 | + |
| 775 | + token = mock_gcsfs.call_args.kwargs["token"] |
| 776 | + assert isinstance(token, GoogleCredentials) |
| 777 | + assert token.token == "token" |
| 778 | + assert token.expiry == datetime(2023, 11, 14, 22, 13, 20) |
| 779 | + |
| 780 | + |
| 781 | +def test_fsspec_gcs_token_without_expiry() -> None: |
| 782 | + """Test that a GCS token without an expiry is passed to gcsfs unchanged.""" |
| 783 | + properties: Properties = {"gcs.oauth2.token": "token"} |
| 784 | + |
| 785 | + with mock.patch("gcsfs.GCSFileSystem") as mock_gcsfs: |
| 786 | + FsspecFileIO(properties=properties).new_input(location="gs://bucket/path/file.parquet") |
| 787 | + |
| 788 | + assert mock_gcsfs.call_args.kwargs["token"] == "token" |
| 789 | + |
| 790 | + |
766 | 791 | @pytest.mark.gcs |
767 | 792 | def test_fsspec_new_input_file_gcs(fsspec_fileio_gcs: FsspecFileIO) -> None: |
768 | 793 | """Test creating a new input file from a fsspec file-io""" |
|
0 commit comments