Skip to content

Commit

Permalink
Append '/' to remote_path for gcs (#84)
Browse files Browse the repository at this point in the history
* Append / to remote_path for gcs

* add unit test for gcs_proxy

Co-authored-by: Honnix <[email protected]>
  • Loading branch information
tnsetting and honnix authored Mar 3, 2020
1 parent 62031a5 commit 235179c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
7 changes: 6 additions & 1 deletion flytekit/interfaces/data/gcs/gcs_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def upload_directory(self, local_path, remote_path):
raise ValueError("Not an GS Key. Please use FQN (GS ARN) of the format gs://...")

GCSProxy._check_binary()
cmd = [GCSProxy._GS_UTIL_CLI, "cp", "-r", _amend_path(local_path), remote_path]

cmd = [GCSProxy._GS_UTIL_CLI,
"cp",
"-r",
_amend_path(local_path),
remote_path if remote_path.endswith("/") else remote_path + "/"]
return _update_cmd_config_and_execute(cmd)

def get_random_path(self):
Expand Down
47 changes: 47 additions & 0 deletions tests/flytekit/unit/interfaces/data/gcs/test_gcs_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from __future__ import absolute_import

import os as _os

import mock as _mock
import pytest as _pytest
from flytekit.interfaces.data.gcs import gcs_proxy as _gcs_proxy


@_pytest.fixture
def mock_update_cmd_config_and_execute():
p = _mock.patch("flytekit.interfaces.data.gcs.gcs_proxy._update_cmd_config_and_execute")
yield p.start()
p.stop()


@_pytest.fixture
def gcs_proxy():
return _gcs_proxy.GCSProxy()


def test_upload_directory(mock_update_cmd_config_and_execute, gcs_proxy):
local_path, remote_path = "/foo/*", "gs://bar/0/"
gcs_proxy.upload_directory(local_path, remote_path)
mock_update_cmd_config_and_execute.assert_called_once_with(
["gsutil", "cp", "-r", local_path, remote_path]
)


def test_upload_directory_padding_wildcard_for_local_path(
mock_update_cmd_config_and_execute, gcs_proxy
):
local_path, remote_path = "/foo", "gs://bar/0/"
gcs_proxy.upload_directory(local_path, remote_path)
mock_update_cmd_config_and_execute.assert_called_once_with(
["gsutil", "cp", "-r", _os.path.join(local_path, "*"), remote_path]
)


def test_upload_directory_padding_slash_for_remote_path(
mock_update_cmd_config_and_execute, gcs_proxy
):
local_path, remote_path = "/foo/*", "gs://bar/0"
gcs_proxy.upload_directory(local_path, remote_path)
mock_update_cmd_config_and_execute.assert_called_once_with(
["gsutil", "cp", "-r", local_path, remote_path + "/"]
)

0 comments on commit 235179c

Please sign in to comment.