Skip to content

Commit 235179c

Browse files
tnsettinghonnix
andauthored
Append '/' to remote_path for gcs (#84)
* Append / to remote_path for gcs * add unit test for gcs_proxy Co-authored-by: Honnix <honnix@users.noreply.github.com>
1 parent 62031a5 commit 235179c

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

flytekit/interfaces/data/gcs/gcs_proxy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ def upload_directory(self, local_path, remote_path):
9999
raise ValueError("Not an GS Key. Please use FQN (GS ARN) of the format gs://...")
100100

101101
GCSProxy._check_binary()
102-
cmd = [GCSProxy._GS_UTIL_CLI, "cp", "-r", _amend_path(local_path), remote_path]
102+
103+
cmd = [GCSProxy._GS_UTIL_CLI,
104+
"cp",
105+
"-r",
106+
_amend_path(local_path),
107+
remote_path if remote_path.endswith("/") else remote_path + "/"]
103108
return _update_cmd_config_and_execute(cmd)
104109

105110
def get_random_path(self):
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)