Skip to content

Commit 4000393

Browse files
authored
test(extractor): added tests for zst and pkg package extractors (#1683)
* fixes #1682
1 parent 86455c1 commit 4000393

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

test/test_extractor.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
import unittest.mock
1010
from io import BytesIO
1111
from os import path
12-
from test.utils import CURL_7_20_0_URL, TMUX_DEB, download_file
12+
from test.utils import (
13+
CURL_7_20_0_URL,
14+
GLIB_PKG_URL,
15+
TAR_ZST_URL,
16+
TMUX_DEB,
17+
download_file,
18+
)
1319
from typing import List
1420
from zipfile import ZipFile, ZipInfo
1521

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

147153

154+
class TestExtractFileZst(TestExtractorBase):
155+
"""Tests for the zst file extractor"""
156+
157+
def setup_method(self):
158+
download_file(TAR_ZST_URL, path.join(self.tempdir, "test.zst"))
159+
160+
@pytest.fixture
161+
def extension_list(self) -> List[str]:
162+
return self.extractor.file_extractors[self.extractor.extract_file_zst]
163+
164+
@pytest.mark.asyncio
165+
async def test_extract_file_zst(self, extension_list: List[str]):
166+
"""Test the zst file extraction"""
167+
async for extracted_path in self.extract_files(
168+
[f"test{extension}" for extension in extension_list]
169+
):
170+
assert path.isfile(path.join(extracted_path, "usr", "bin", "tar"))
171+
172+
173+
class TestExtractFilePkg(TestExtractorBase):
174+
"""Tests for pkg file extractor"""
175+
176+
def setup_method(self):
177+
assert inpath("tar") or inpath("7z"), "Required tools 'tar' or '7z' not found"
178+
download_file(GLIB_PKG_URL, path.join(self.tempdir, "test.pkg"))
179+
180+
@pytest.fixture
181+
def extension_list(self) -> List[str]:
182+
return self.extractor.file_extractors[self.extractor.extract_file_pkg]
183+
184+
@pytest.mark.asyncio
185+
async def test_extract_file_pkg(self, extension_list: List[str]):
186+
"""Test the pkg file extraction"""
187+
async for extracted_path in self.extract_files(
188+
[f"test{extension}" for extension in extension_list]
189+
):
190+
assert path.isfile(path.join(extracted_path, "usr", "local", "bin", "gio"))
191+
192+
148193
class TestExtractFileRpmWithZstd(TestExtractorBase):
149194
"""Tests for the rpm file extractor (zstd/windows)"""
150195

test/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
)
2121
TMUX_DEB_NAME = "tmux_1.8-5_amd64.deb"
2222
TMUX_DEB = "https://mirrors.cat.pdx.edu/ubuntu/pool/main/t/tmux/" + TMUX_DEB_NAME
23+
TAR_ZST_NAME = "tar-1.34-1-x86_64.pkg.tar.zst"
24+
TAR_ZST_URL = "https://ftp5.gwdg.de/pub/linux/archlinux/core/os/x86_64/" + TAR_ZST_NAME
25+
GLIB_PKG_NAME = "glib-2.70.4_3,2.pkg"
26+
GLIB_PKG_URL = (
27+
"https://pkg.freebsd.org/FreeBSD:12:aarch64/quarterly/All/" + GLIB_PKG_NAME
28+
)
2329

2430

2531
class TempDirTest:

0 commit comments

Comments
 (0)