2021-03-21 18:05:11 +00:00
|
|
|
#!/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
|
2021-08-24 18:13:04 +00:00
|
|
|
BIN = PROJECT_ROOT.joinpath("build", "src", "nix-eval-jobs")
|
2021-03-21 18:05:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def common_test(extra_args: List[str]) -> None:
|
|
|
|
with TemporaryDirectory() as tempdir:
|
|
|
|
cmd = [str(BIN), "--gc-roots-dir", tempdir] + extra_args
|
|
|
|
res = subprocess.run(
|
|
|
|
cmd,
|
|
|
|
cwd=TEST_ROOT.joinpath("assets"),
|
|
|
|
text=True,
|
|
|
|
check=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
)
|
2021-08-25 08:36:32 +00:00
|
|
|
|
2021-08-25 17:43:35 +00:00
|
|
|
results = [json.loads(r) for r in res.stdout.split("\n") if r]
|
|
|
|
assert len(results) == 2
|
2021-08-25 08:36:32 +00:00
|
|
|
|
2021-08-25 17:43:35 +00:00
|
|
|
built_job = results[0]
|
|
|
|
assert built_job["attr"] == "builtJob"
|
2021-08-26 21:56:23 +00:00
|
|
|
assert built_job["name"] == "job1"
|
2021-08-25 17:43:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
substituted_job = results[1]
|
|
|
|
assert substituted_job["attr"] == "substitutedJob"
|
2021-08-26 21:56:23 +00:00
|
|
|
assert substituted_job["name"].startswith("hello-")
|
2021-03-21 18:05:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_flake() -> None:
|
2021-08-26 23:48:11 +00:00
|
|
|
common_test(["--flake", ".#hydraJobs"])
|
2021-03-21 18:05:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_expression() -> None:
|
|
|
|
common_test(["ci.nix"])
|