|
| 1 | +from __future__ import absolute_import |
| 2 | + |
| 3 | +import os as _os |
| 4 | + |
| 5 | +import mock as _mock |
| 6 | +import pytest as _pytest |
| 7 | +from flytekit.interfaces.data.gcs import gcs_proxy as _gcs_proxy |
| 8 | + |
| 9 | + |
| 10 | +@_pytest.fixture |
| 11 | +def mock_update_cmd_config_and_execute(): |
| 12 | + p = _mock.patch("flytekit.interfaces.data.gcs.gcs_proxy._update_cmd_config_and_execute") |
| 13 | + yield p.start() |
| 14 | + p.stop() |
| 15 | + |
| 16 | + |
| 17 | +@_pytest.fixture |
| 18 | +def gcs_proxy(): |
| 19 | + return _gcs_proxy.GCSProxy() |
| 20 | + |
| 21 | + |
| 22 | +def test_upload_directory(mock_update_cmd_config_and_execute, gcs_proxy): |
| 23 | + local_path, remote_path = "/foo/*", "gs://bar/0/" |
| 24 | + gcs_proxy.upload_directory(local_path, remote_path) |
| 25 | + mock_update_cmd_config_and_execute.assert_called_once_with( |
| 26 | + ["gsutil", "cp", "-r", local_path, remote_path] |
| 27 | + ) |
| 28 | + |
| 29 | + |
| 30 | +def test_upload_directory_padding_wildcard_for_local_path( |
| 31 | + mock_update_cmd_config_and_execute, gcs_proxy |
| 32 | +): |
| 33 | + local_path, remote_path = "/foo", "gs://bar/0/" |
| 34 | + gcs_proxy.upload_directory(local_path, remote_path) |
| 35 | + mock_update_cmd_config_and_execute.assert_called_once_with( |
| 36 | + ["gsutil", "cp", "-r", _os.path.join(local_path, "*"), remote_path] |
| 37 | + ) |
| 38 | + |
| 39 | + |
| 40 | +def test_upload_directory_padding_slash_for_remote_path( |
| 41 | + mock_update_cmd_config_and_execute, gcs_proxy |
| 42 | +): |
| 43 | + local_path, remote_path = "/foo/*", "gs://bar/0" |
| 44 | + gcs_proxy.upload_directory(local_path, remote_path) |
| 45 | + mock_update_cmd_config_and_execute.assert_called_once_with( |
| 46 | + ["gsutil", "cp", "-r", local_path, remote_path + "/"] |
| 47 | + ) |
0 commit comments