Skip to content

Commit

Permalink
test(extractor): added tests for zst and pkg package extractors (#1683)
Browse files Browse the repository at this point in the history
* fixes #1682
  • Loading branch information
yashugarg authored Jun 16, 2022
1 parent 86455c1 commit 4000393
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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

0 comments on commit 4000393

Please sign in to comment.