Skip to content

Commit

Permalink
tests: Reproducer for reading large file over SCP
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
  • Loading branch information
Jakuje committed Jun 26, 2024
1 parent 2fa6a91 commit 39d43d0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/unit/scp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Tests suite for scp."""

import random
import uuid

import pytest
Expand Down Expand Up @@ -71,3 +72,31 @@ def test_get_existing_local(dst_path_exists, src_path, ssh_scp, transmit_payload
"""Check that SCP file download works and overrides local file if it exists."""
ssh_scp.get(str(src_path), str(dst_path_exists))
assert dst_path_exists.read_bytes() == transmit_payload


@pytest.fixture
def large_payload():
"""Generate a large test payload."""
# buffer of random 1024 bytes -- just printable ones for easier debugging
rands = []
for _ in range(1024):
rnd = chr(random.randint(ord(' '), ord('~')))
rands.append(rnd)
rand = ''.join(rands)
# .. repeated 65 times
repeat = 65
return ''.join(rand for _ in range(repeat)).encode()


@pytest.fixture
def src_path_large(tmp_path, large_payload):
"""Return a remote path that is a file larger than 64k B, which is the most libssh can read at once."""
path = tmp_path / 'large.txt'
path.write_bytes(large_payload)
return path


def test_get_large(dst_path, src_path_large, ssh_scp, large_payload):
"""Check that SCP file download gets over 64kB of data."""
ssh_scp.get(str(src_path_large), str(dst_path))
assert dst_path.read_bytes() == large_payload

0 comments on commit 39d43d0

Please sign in to comment.