From 5e2412ea7e3a8725355a07bed1f3cccc5506edcf Mon Sep 17 00:00:00 2001 From: "Commentator2.0" Date: Sun, 21 Sep 2025 16:21:44 +0200 Subject: [PATCH] tests/functional2: migrate add.sh Change-Id: I699929b61db19a4ab7bea8281df830de9fea6d04 --- tests/functional/add.sh | 34 -------------------- tests/functional/meson.build | 1 - tests/functional/symlink | 1 - tests/functional2/store/test_add.py | 50 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 36 deletions(-) delete mode 100644 tests/functional/add.sh delete mode 120000 tests/functional/symlink create mode 100644 tests/functional2/store/test_add.py diff --git a/tests/functional/add.sh b/tests/functional/add.sh deleted file mode 100644 index 38ce9d2d9..000000000 --- a/tests/functional/add.sh +++ /dev/null @@ -1,34 +0,0 @@ -source common.sh - -expectStderr 1 nix-store --add-fixed sha256 . | grep "cannot import directory using flat ingestion" -expectStderr 1 nix-store --add-fixed sha256 ./symlink | grep "cannot import symlink using flat ingestion" - -expectStderr 1 nix-store --add-fixed sha1 . | grep "cannot import directory using flat ingestion" -expectStderr 1 nix-store --add-fixed sha1 ./symlink | grep "cannot import symlink using flat ingestion" - -path1=$(nix-store --add ./dummy) -echo $path1 - -path2=$(nix-store --add-fixed sha256 --recursive ./dummy) -echo $path2 - -if test "$path1" != "$path2"; then - echo "nix-store --add and --add-fixed mismatch" - exit 1 -fi - -path3=$(nix-store --add-fixed sha256 ./dummy) -echo $path3 -test "$path1" != "$path3" || exit 1 - -path4=$(nix-store --add-fixed sha1 --recursive ./dummy) -echo $path4 -test "$path1" != "$path4" || exit 1 - -hash1=$(nix-store -q --hash $path1) -echo $hash1 - -hash2=$(nix-hash --type sha256 --base32 ./dummy) -echo $hash2 - -test "$hash1" = "sha256:$hash2" diff --git a/tests/functional/meson.build b/tests/functional/meson.build index cc8d0a46e..4c0ff2513 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -116,7 +116,6 @@ functional_tests_scripts = [ 'logging.sh', 'export.sh', 'config.sh', - 'add.sh', 'local-store.sh', 'filter-source.sh', 'misc.sh', diff --git a/tests/functional/symlink b/tests/functional/symlink deleted file mode 120000 index 429f42921..000000000 --- a/tests/functional/symlink +++ /dev/null @@ -1 +0,0 @@ -add.sh \ No newline at end of file diff --git a/tests/functional2/store/test_add.py b/tests/functional2/store/test_add.py new file mode 100644 index 000000000..ab593b8e1 --- /dev/null +++ b/tests/functional2/store/test_add.py @@ -0,0 +1,50 @@ +import pytest + +from functional2.testlib.fixtures.file_helper import with_files, File, AssetSymlink, Symlink +from functional2.testlib.fixtures.nix import Nix + + +@with_files({"file-link": AssetSymlink("./test_add.py"), "dir-link": Symlink(".")}) +@pytest.mark.parametrize("hash_fn", ["sha1", "sha256"]) +@pytest.mark.parametrize("path", [".", "./file-link", "dir-link"]) +def test_invalid_flat_add(nix: Nix, hash_fn: str, path: str): + cmd = nix.nix_store(["--add-fixed", hash_fn, path]) + res = cmd.run().expect(1) + assert ( + f"cannot import {'directory' if path == '.' else 'symlink'} using flat ingestion" + in res.stderr_s + ) + + +@pytest.fixture +def blank_add_path(nix: Nix) -> str: + return nix.nix_store(["--add", "./dummy"]).run().ok().stdout_plain + + +@with_files({"dummy": File("Hello World\n")}) +def test_add_fixed(nix: Nix, blank_add_path: str): + args = ["--add-fixed", "sha256", "./dummy"] + res = nix.nix_store(args).run().ok() + assert res.stdout_plain != blank_add_path + + +@with_files({"dummy": File("Hello World\n")}) +def test_add_fixed_rec(nix: Nix, blank_add_path: str): + args = ["--add-fixed", "sha256", "--recursive", "./dummy"] + res = nix.nix_store(args).run().ok() + assert res.stdout_plain == blank_add_path + + +@with_files({"dummy": File("Hello World\n")}) +def test_add_fixed_sha1(nix: Nix, blank_add_path: str): + res = nix.nix_store(["--add-fixed", "sha1", "--recursive", "./dummy"]).run().ok() + assert res.stdout_plain != blank_add_path + + +@with_files({"dummy": File("Hello World\n")}) +def test_hash(nix: Nix, blank_add_path: str): + res = nix.nix_store(["-q", "--hash", blank_add_path]).run().ok() + hash1 = res.stdout_plain + res = nix.nix(["--type", "sha256", "--base32", "./dummy"], "nix-hash").run().ok() + hash2 = f"sha256:{res.stdout_plain}" + assert hash1 == hash2