Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
tests: Cover copy_required_tools_from_controller_cache_to_target_env()
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Jan 27, 2022
1 parent fb2e238 commit 9a6909b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bahub/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def copy_encryption_keys_from_controller_to_target_env(src_fs: FilesystemInterfa
dst_fs.copy_to(key_path, f"/tmp/.gpg.{key_type}")


def copy_required_tools_from_controller_cache_to_target_env(local_cache_fs: FilesystemInterface, dst_fs: FilesystemInterface, io: IO,
def copy_required_tools_from_controller_cache_to_target_env(local_cache_fs: FilesystemInterface,
dst_fs: FilesystemInterface, io: IO,
bin_path: str, versions_path: str, local_versions_path: str,
binaries: List[RequiredBinary]):
"""
Expand Down
73 changes: 70 additions & 3 deletions test/test_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from rkd.api.inputoutput import BufferedSystemIO
from rkd.api.testing import BasicTestingCase
from bahub.bin import RequiredBinary, RequiredBinaryFromGithubRelease, RequiredBinaryFromGithubReleasePackedInArchive, \
download_required_tools, copy_encryption_keys_from_controller_to_target_env
download_required_tools, copy_encryption_keys_from_controller_to_target_env, \
copy_required_tools_from_controller_cache_to_target_env
from bahub.fs import FilesystemInterface


Expand Down Expand Up @@ -59,7 +60,7 @@ def __getattr__(self, item):

class TestDownloadRequiredTools(BasicTestingCase):
"""
Covers download_required_tools
Covers download_required_tools()
"""

def test_downloads_and_unpacks_archive(self):
Expand Down Expand Up @@ -177,7 +178,7 @@ def test_file_is_downloaded_and_not_unpacked_if_not_an_archive(self):

class TestEncryptionKeysCopying(BasicTestingCase):
"""
Covers copy_encryption_keys_from_controller_to_target_env
Covers copy_encryption_keys_from_controller_to_target_env()
"""

def test_copies_only_keys_that_exists(self):
Expand Down Expand Up @@ -210,3 +211,69 @@ def test_copies_only_keys_that_exists(self):
dst_fs.callstack
)


class TestToolsTransferFromLocalCacheToTargetFilesystem(BasicTestingCase):
"""
Covers copy_required_tools_from_controller_cache_to_target_env()
"""

def test_no_binaries_triggers_early_exit(self):
fs: Union[FilesystemInterface, FSMock] = FSMock()
io = BufferedSystemIO()
io.set_log_level("debug")

copy_required_tools_from_controller_cache_to_target_env(
local_cache_fs=fs, dst_fs=fs, bin_path="/opt/bin", versions_path="/opt/bin/.versions",
local_versions_path="/tmp/.versions",
binaries=[], # this is empty,
io=io
)

self.assertIn("All binaries are up-to-date", io.get_value())

def test_archive_is_copied_and_tools_are_linked(self):
local_cache_fs: Union[FilesystemInterface, FSMock] = FSMock()
dst_fs: Union[FilesystemInterface, FSMock] = FSMock()
io = BufferedSystemIO()
io.set_log_level("debug")

copy_required_tools_from_controller_cache_to_target_env(
local_cache_fs=local_cache_fs, dst_fs=dst_fs, bin_path="/opt/bin", versions_path="/opt/bin/.versions",
local_versions_path="/tmp/.versions",
binaries=[
RequiredBinaryFromGithubReleasePackedInArchive(
project_name="riotkit-org/tracexit",
version="1.6.1",
binary_name="tracexit",
archive_name="tracexit-1.0.0-amd64.tar.gz"
),
RequiredBinaryFromGithubReleasePackedInArchive(
project_name="riotkit-org/br-backup-maker",
version="2.1.3.7",
binary_name="br-backup-maker",
archive_name="br-backup-maker-1.0.0-amd64.tar.gz"
)
],
io=io
)

# versions are packed at source filesystem
self.assertIn('pack', str(local_cache_fs.callstack))
self.assertIn("'v1.6.1-tracexit', 'v2.1.3.7-br-backup-maker'", str(local_cache_fs.callstack))

# versions are unpacked at target filesystem
self.assertIn("copy_to", str(dst_fs.callstack))
self.assertIn(
['unpack', ('/tmp/.backup-tools.tar.gz', '/opt/bin/.versions'), {}],
dst_fs.callstack
)

# files are linked
self.assertIn(
['link', ('/opt/bin/.versions/v1.6.1-tracexit', '/opt/bin/tracexit'), {}],
dst_fs.callstack
)
self.assertIn(
['link', ('/opt/bin/.versions/v2.1.3.7-br-backup-maker', '/opt/bin/br-backup-maker'), {}],
dst_fs.callstack
)

0 comments on commit 9a6909b

Please sign in to comment.