Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(extractor): added tests for zst and pkg package extractors #1683

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion test/test_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import unittest.mock
from io import BytesIO
from os import path
from test.utils import CURL_7_20_0_URL, TMUX_DEB, download_file
from test.utils import (
CURL_7_20_0_URL,
GLIB_PKG_URL,
TAR_ZST_URL,
TMUX_DEB,
download_file,
)
from typing import List
from zipfile import ZipFile, ZipInfo

Expand Down Expand Up @@ -145,6 +151,45 @@ async def test_extract_file_rpm_no_rpm2cipo(self, extension_list: List[str]):
mock_aio_run_command.assert_not_called()


class TestExtractFileZst(TestExtractorBase):
"""Tests for the zst file extractor"""

def setup_method(self):
download_file(TAR_ZST_URL, path.join(self.tempdir, "test.zst"))

@pytest.fixture
def extension_list(self) -> List[str]:
return self.extractor.file_extractors[self.extractor.extract_file_zst]

@pytest.mark.asyncio
async def test_extract_file_zst(self, extension_list: List[str]):
"""Test the zst file extraction"""
async for extracted_path in self.extract_files(
[f"test{extension}" for extension in extension_list]
):
assert path.isfile(path.join(extracted_path, "usr", "bin", "tar"))


class TestExtractFilePkg(TestExtractorBase):
"""Tests for pkg file extractor"""

def setup_method(self):
assert inpath("tar") or inpath("7z"), "Required tools 'tar' or '7z' not found"
download_file(GLIB_PKG_URL, path.join(self.tempdir, "test.pkg"))

@pytest.fixture
def extension_list(self) -> List[str]:
return self.extractor.file_extractors[self.extractor.extract_file_pkg]

@pytest.mark.asyncio
async def test_extract_file_pkg(self, extension_list: List[str]):
"""Test the pkg file extraction"""
async for extracted_path in self.extract_files(
[f"test{extension}" for extension in extension_list]
):
assert path.isfile(path.join(extracted_path, "usr", "local", "bin", "gio"))


class TestExtractFileRpmWithZstd(TestExtractorBase):
"""Tests for the rpm file extractor (zstd/windows)"""

Expand Down
6 changes: 6 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
)
TMUX_DEB_NAME = "tmux_1.8-5_amd64.deb"
TMUX_DEB = "https://mirrors.cat.pdx.edu/ubuntu/pool/main/t/tmux/" + TMUX_DEB_NAME
TAR_ZST_NAME = "tar-1.34-1-x86_64.pkg.tar.zst"
TAR_ZST_URL = "https://ftp5.gwdg.de/pub/linux/archlinux/core/os/x86_64/" + TAR_ZST_NAME
GLIB_PKG_NAME = "glib-2.70.4_3,2.pkg"
GLIB_PKG_URL = (
"https://pkg.freebsd.org/FreeBSD:12:aarch64/quarterly/All/" + GLIB_PKG_NAME
)


class TempDirTest:
Expand Down