clan-cli: Fix single file upload in upload.py, add test for edge case
This commit is contained in:
@@ -66,7 +66,14 @@ def upload(
|
||||
if host.user != "root":
|
||||
sudo = "sudo -- "
|
||||
|
||||
cmd = 'rm -rf "$0" && mkdir -m "$1" -p "$0" && tar -C "$0" -xzf -'
|
||||
cmd = None
|
||||
if local_src.is_dir():
|
||||
cmd = 'rm -rf "$0" && mkdir -m "$1" -p "$0" && tar -C "$0" -xzf -'
|
||||
elif local_src.is_file():
|
||||
cmd = 'rm -f "$0" && tar -C "$(dirname "$0")" -xzf -'
|
||||
else:
|
||||
msg = f"Unsupported source type: {local_src}"
|
||||
raise ClanError(msg)
|
||||
|
||||
# TODO accept `input` to be an IO object instead of bytes so that we don't have to read the tarfile into memory.
|
||||
with tar_path.open("rb") as f:
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.ssh.host import Host, HostKeyCheck
|
||||
from clan_cli.ssh.upload import upload
|
||||
from clan_cli.tests.fixtures_flakes import ClanFlake
|
||||
from clan_cli.tests.helpers import cli
|
||||
|
||||
@@ -9,6 +11,25 @@ if TYPE_CHECKING:
|
||||
from .age_keys import KeyPair
|
||||
|
||||
|
||||
@pytest.mark.with_core
|
||||
def test_upload_single_file(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
temporary_home: Path,
|
||||
hosts: list[Host],
|
||||
) -> None:
|
||||
host = hosts[0]
|
||||
host.host_key_check = HostKeyCheck.NONE
|
||||
|
||||
src_file = temporary_home / "test.txt"
|
||||
src_file.write_text("test")
|
||||
dest_file = temporary_home / "test_dest.txt"
|
||||
|
||||
upload(host, src_file, dest_file)
|
||||
|
||||
assert dest_file.exists()
|
||||
assert dest_file.read_text() == "test"
|
||||
|
||||
|
||||
@pytest.mark.with_core
|
||||
def test_secrets_upload(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
|
||||
Reference in New Issue
Block a user