Skip to content

Commit

Permalink
add test case for zip label order
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Aug 5, 2023
1 parent a78c6e5 commit 3a935da
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import contextlib
import errno
import os
import uuid

import pytest

Expand All @@ -27,7 +28,7 @@
import mock # type: ignore[no-redef,import]

if TYPE_CHECKING:
from typing import Any, Iterator, Tuple
from typing import Any, Iterator, List, Tuple


def extract_perms(path):
Expand Down Expand Up @@ -140,6 +141,26 @@ def test_chroot_zip():
assert b"data" == zip.read("directory/subdirectory/file")


def test_chroot_zip_preserves_label_order():
# type: () -> None
"""Verify that the order of the labels presented to ``Chroot.zip()`` transfers to the order
of the zip file entries."""
with temporary_dir() as tmp:
chroot = Chroot(os.path.join(tmp, "chroot"))

ordered_labels = [] # type: List[str]
for i in range(10):
label = uuid.uuid4().hex
chroot.write(b"", "{}-{}".format(uuid.uuid4().hex, i), label=label)
ordered_labels.append(label)

zip_dst = os.path.join(tmp, "chroot.zip")
chroot.zip(zip_dst, labels=ordered_labels)
with open_zip(zip_dst) as zip:
for i, filename in enumerate(zip.namelist()):
assert filename.endswith("-{}".format(i))


def test_chroot_zip_symlink():
# type: () -> None
with temporary_dir() as tmp:
Expand Down

0 comments on commit 3a935da

Please sign in to comment.