diff --git a/tests/functional/compression-levels.sh b/tests/functional/compression-levels.sh deleted file mode 100644 index 85f12974a..000000000 --- a/tests/functional/compression-levels.sh +++ /dev/null @@ -1,22 +0,0 @@ -source common.sh - -clearStore -clearCache - -outPath=$(nix-build dependencies.nix --no-out-link) - -cacheURI="file://$cacheDir?compression=xz&compression-level=0" - -nix copy --to $cacheURI $outPath - -FILESIZES=$(cat ${cacheDir}/*.narinfo | awk '/FileSize: /{sum+=$2}END{print sum}') - -clearCache - -cacheURI="file://$cacheDir?compression=xz&compression-level=5" - -nix copy --to $cacheURI $outPath - -FILESIZES2=$(cat ${cacheDir}/*.narinfo | awk '/FileSize: /{sum+=$2}END{print sum}') - -[[ $FILESIZES -gt $FILESIZES2 ]] diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 53fd22560..2b8e46bd4 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -117,7 +117,6 @@ functional_tests_scripts = [ 'shell.sh', 'brotli.sh', 'zstd.sh', - 'compression-levels.sh', 'nix-copy-ssh.sh', 'nix-copy-ssh-ng.sh', 'pre-hook.sh', diff --git a/tests/functional2/store/cache/__init__.py b/tests/functional2/store/cache/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/functional2/store/cache/test_compression_levels.py b/tests/functional2/store/cache/test_compression_levels.py new file mode 100644 index 000000000..1a6d869f2 --- /dev/null +++ b/tests/functional2/store/cache/test_compression_levels.py @@ -0,0 +1,44 @@ +import re +from pathlib import Path + +from functional2.testlib.fixtures.file_helper import with_files +from functional2.testlib.fixtures.nix import Nix +from functional2.testlib.utils import get_global_asset_pack + + +@with_files(get_global_asset_pack("dependencies")) +def test_compression_levels(nix: Nix): + cache_dir1 = nix.env.dirs.cache_dir / "test1" + cache_dir2 = nix.env.dirs.cache_dir / "test2" + + nix.settings.feature("nix-command") + res = nix.nix_build(["dependencies.nix", "--no-out-link"]).run().ok() + out_path = res.stdout_plain + + def get_size_for_level(level: int, c_dir: Path) -> int: + cpy_res = ( + nix.nix( + [ + "copy", + "--to", + f"file://{c_dir}?compression=xz&compression-level={level}", + out_path, + ], + build=True, + ) + .run() + .ok() + ) + assert "copying 4 paths..." in cpy_res.stderr_plain + + size = 0 + for f in c_dir.glob("*.narinfo"): + size += int(re.search(r"FileSize: (\d+)\n", f.read_text()).group(1)) + + return size + + size_0 = get_size_for_level(0, cache_dir1) + + size_5 = get_size_for_level(5, cache_dir2) + + assert size_0 > size_5