Skip to content

Commit

Permalink
Go 1.21: Ignore the sumdb directory in the test_packages test
Browse files Browse the repository at this point in the history
This directory only contains records regarding the toolchain download.
More importantly though, these tlog records change in time so while
still providing accurate verification information on a toolchain
download we must ensure determinism in the test execution, hence we
have to ignore this directory.

Signed-off-by: Bruno Pimentel <bpimente@redhat.com>
  • Loading branch information
brunoapimentel authored and eskultety committed May 28, 2024
1 parent d9d1620 commit f5ad451
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 5 additions & 3 deletions tests/helper_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
from typing import Union


def assert_directories_equal(dir_a, dir_b):
def assert_directories_equal(dir_a, dir_b, ignore_files=[]):
"""
Check recursively directories have equal content.
:param dir_a: first directory to check
:param dir_b: second directory to check
"""
dirs_cmp = filecmp.dircmp(dir_a, dir_b)
ignore_files = list(set(filecmp.DEFAULT_IGNORES).union(ignore_files))
dirs_cmp = filecmp.dircmp(dir_a, dir_b, ignore=ignore_files)

assert (
len(dirs_cmp.left_only) == 0
), f"Found files: {dirs_cmp.left_only} in {dir_a}, but not {dir_b}."
Expand All @@ -28,7 +30,7 @@ def assert_directories_equal(dir_a, dir_b):
for common_dir in dirs_cmp.common_dirs:
inner_a = os.path.join(dir_a, common_dir)
inner_b = os.path.join(dir_b, common_dir)
assert_directories_equal(inner_a, inner_b)
assert_directories_equal(inner_a, inner_b, ignore_files)


class Symlink(str):
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ def test_packages(env_package, env_name, test_env, tmpdir):
client.download_and_extract_archive(completed_response.id, tmpdir)
source_path = tmpdir.join(f"download_{str(completed_response.id)}")
expected_files = env_data["expected_files"]
utils.assert_expected_files(source_path, expected_files, tmpdir)

# File or directory names that will be ignored when checking the request output contents.
# Note that these do not represent absolute paths, so any file or directory that matches
# a name will be ignored.
ignore_files = env_data.get("ignore_files", {})

utils.assert_expected_files(source_path, expected_files, tmpdir, ignore_files)

image_contents = utils.parse_image_contents(env_data.get("content_manifest"))
utils.assert_content_manifest(client, completed_response.id, image_contents)
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def assert_elements_from_response(response_data, expected_response_data):
)


def assert_expected_files(source_path, expected_files, tmpdir):
def assert_expected_files(source_path, expected_files, tmpdir, ignore_files={}):
"""
Check that the source path includes expected files in directories.
Expand Down Expand Up @@ -397,8 +397,13 @@ def assert_expected_files(source_path, expected_files, tmpdir):
assert os.path.isdir(
expected_package_root_dir
), f"Wrong directory path {expected_package_root_dir}."

ignore_files_for_dir = ignore_files.get(dir_to_check, [])

# Compare and assert files in directory with expected data
assert_directories_equal(package_root_dir, expected_package_root_dir)
assert_directories_equal(
package_root_dir, expected_package_root_dir, ignore_files_for_dir
)
# Delete temporary data
for temp_data in [deps_data_path, expected_data_path, expected_archive]:
if os.path.isdir(temp_data):
Expand Down

0 comments on commit f5ad451

Please sign in to comment.