Skip to content

Commit

Permalink
tests: Reproducer for ansible#341
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
  • Loading branch information
Jakuje committed Aug 30, 2024
1 parent a60a6cb commit 038e7e7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/unit/sftp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"""Tests suite for sftp."""

import random
import string
import uuid

import pytest
Expand Down Expand Up @@ -63,3 +65,29 @@ def test_get(dst_path, src_path, sftp_session, transmit_payload):
"""Check that SFTP file download works."""
sftp_session.get(str(src_path), str(dst_path))
assert dst_path.read_bytes() == transmit_payload


@pytest.fixture
def large_payload():
"""Generate a large 1025 byte (1024 + 1B) test payload."""
payload_len = 1024 + 1
random_bytes = [ord(random.choice(string.printable)) for _ in range(payload_len)]
return bytes(random_bytes)


@pytest.fixture
def src_path_large(tmp_path, large_payload):
"""Return a remote path to a 1025 byte-sized file.
The pylibssh chunk size is 1024 so the test needs a file that would
execute at least two loops.
"""
path = tmp_path / 'large.txt'
path.write_bytes(large_payload)
return path


def test_get_large(dst_path, src_path_large, sftp_session, large_payload):
"""Check that SFTP can download large file."""
sftp_session.get(str(src_path_large), str(dst_path))
assert dst_path.read_bytes() == large_payload

0 comments on commit 038e7e7

Please sign in to comment.