Skip to content

Commit c2e0cb1

Browse files
committed
tests: Reproducer for reading large file over SCP
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
1 parent 325a241 commit c2e0cb1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/unit/scp_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Tests suite for scp."""
44

55
import os
6+
import random
67
import uuid
78

89
import pytest
@@ -89,3 +90,31 @@ def test_get_existing_local(pre_existing_file_path, src_path, ssh_scp, transmit_
8990
"""Check that SCP file download works and overwrites local file if it exists."""
9091
ssh_scp.get(str(src_path), str(pre_existing_file_path))
9192
assert pre_existing_file_path.read_bytes() == transmit_payload
93+
94+
95+
@pytest.fixture
96+
def large_payload():
97+
"""Generate a large test payload."""
98+
# buffer of random 1024 bytes -- just printable ones for easier debugging
99+
rands = []
100+
for _ in range(1024):
101+
rnd = chr(random.randint(ord(' '), ord('~')))
102+
rands.append(rnd)
103+
rand = ''.join(rands)
104+
# .. repeated 65 times
105+
repeat = 65
106+
return ''.join(rand for _ in range(repeat)).encode()
107+
108+
109+
@pytest.fixture
110+
def src_path_large(tmp_path, large_payload):
111+
"""Return a remote path that is a file larger than 64k B, which is the most libssh can read at once."""
112+
path = tmp_path / 'large.txt'
113+
path.write_bytes(large_payload)
114+
return path
115+
116+
117+
def test_get_large(dst_path, src_path_large, ssh_scp, large_payload):
118+
"""Check that SCP file download gets over 64kB of data."""
119+
ssh_scp.get(str(src_path_large), str(dst_path))
120+
assert dst_path.read_bytes() == large_payload

0 commit comments

Comments
 (0)