tests: migrate derivation-json.sh

Change-Id: I8a648231677bde28611dc9511e3a03d87608e7b4
This commit is contained in:
rootile
2026-06-22 18:16:17 +00:00
committed by Rutile
parent 30ca2e38c4
commit 8902b78442
3 changed files with 32 additions and 13 deletions
-12
View File
@@ -1,12 +0,0 @@
source common.sh
drvPath=$(nix-instantiate simple.nix)
nix derivation show $drvPath | jq .[] > $TEST_HOME/simple.json
drvPath2=$(nix derivation add < $TEST_HOME/simple.json)
[[ "$drvPath" = "$drvPath2" ]]
# Input addressed derivations cannot be renamed.
jq '.name = "foo"' < $TEST_HOME/simple.json | expectStderr 1 nix derivation add | grepQuiet "has incorrect output"
-1
View File
@@ -86,7 +86,6 @@ functional_tests_scripts = [
'nix-copy-ssh-ng.sh',
'pre-hook.sh',
'post-hook.sh',
'derivation-json.sh',
'db-migration.sh',
'bash-profile.sh',
'flakes/show.sh',
+32
View File
@@ -0,0 +1,32 @@
import json
from testlib.utils import get_global_asset_pack
from testlib.fixtures.file_helper import with_files
from testlib.fixtures.nix import Nix
@with_files(get_global_asset_pack("simple-drv"))
def test_add_json(nix: Nix):
drv_path = nix.nix_instantiate(["simple.nix"]).run().ok().stdout_plain
drv_json = nix.nix(["derivation", "show", drv_path], flake=True).run().json()
drv_json = next(iter(drv_json.values()))
drv_path2 = (
nix.nix(["derivation", "add"], flake=True)
.with_stdin(json.dumps(drv_json).encode())
.run()
.ok()
.stdout_plain
)
assert drv_path == drv_path2
drv_json["name"] = "foo"
res = (
nix.nix(["derivation", "add"], flake=True)
.with_stdin(json.dumps(drv_json).encode())
.run()
.expect(1)
)
assert "has incorrect output" in res.stderr_plain