nix-eval-jobs/tests/test_eval.py
adisbladis 3268f3a6af Add flag to enable meta
I removed meta from the output in 434376f8e1 with the intention of adding it back gated by a flag, but that never happened.

Adding meta is quite a substantial increase in output size and has some non-trivial performance impact at scale, so it's best to leave it as opt-in.
2022-01-06 13:40:21 +13:00

47 lines
1.3 KiB
Python

#!/usr/bin/env python3
import subprocess
import json
from tempfile import TemporaryDirectory
from pathlib import Path
from typing import List
TEST_ROOT = Path(__file__).parent.resolve()
PROJECT_ROOT = TEST_ROOT.parent
BIN = PROJECT_ROOT.joinpath("build", "src", "nix-eval-jobs")
def common_test(extra_args: List[str]) -> None:
with TemporaryDirectory() as tempdir:
cmd = [str(BIN), "--gc-roots-dir", tempdir, "--meta"] + extra_args
res = subprocess.run(
cmd,
cwd=TEST_ROOT.joinpath("assets"),
text=True,
check=True,
stdout=subprocess.PIPE,
)
results = [json.loads(r) for r in res.stdout.split("\n") if r]
assert len(results) == 2
built_job = results[0]
assert built_job["attr"] == "builtJob"
assert built_job["name"] == "job1"
assert built_job["outputs"]["out"].startswith("/nix/store")
assert built_job["drvPath"].endswith(".drv")
assert built_job["meta"]['broken'] is False
substituted_job = results[1]
assert substituted_job["attr"] == "substitutedJob"
assert substituted_job["name"].startswith("hello-")
assert substituted_job["meta"]['broken'] is False
def test_flake() -> None:
common_test(["--flake", ".#hydraJobs"])
def test_expression() -> None:
common_test(["ci.nix"])