testing: migrate flakes/flakes.sh (part 5)
build bare repo, build tarball, lock path urls without repo Change-Id: I7cb7494dcf29ec9b88c923c54a798685725785a1
This commit is contained in:
@@ -11,7 +11,6 @@ flake3Dir=$TEST_ROOT/flake3
|
||||
flake5Dir=$TEST_ROOT/flake5
|
||||
flake7Dir=$TEST_ROOT/flake7
|
||||
nonFlakeDir=$TEST_ROOT/nonFlake
|
||||
flakeGitBare=$TEST_ROOT/flakeGitBare
|
||||
|
||||
for repo in $flake1Dir $flake2Dir $flake3Dir $flake7Dir $nonFlakeDir; do
|
||||
# Give one repo a non-main initial branch.
|
||||
@@ -452,12 +451,7 @@ nix flake update --flake "$flake3Dir"
|
||||
[[ $(jq -c .nodes.flake2.inputs.flake1 "$flake3Dir/flake.lock") =~ '["foo"]' ]]
|
||||
[[ $(jq .nodes.foo.locked.url "$flake3Dir/flake.lock") =~ flake7 ]]
|
||||
|
||||
# Test git+file with bare repo.
|
||||
rm -rf $flakeGitBare
|
||||
git clone --bare $flake1Dir $flakeGitBare
|
||||
nix build -o $TEST_ROOT/result git+file://$flakeGitBare
|
||||
|
||||
# Test path flakes.
|
||||
# prepare path flakes.
|
||||
mkdir -p $flake5Dir
|
||||
writeDependentFlake $flake5Dir
|
||||
nix flake lock path://$flake5Dir
|
||||
@@ -465,17 +459,6 @@ nix flake lock path://$flake5Dir
|
||||
# Test tarball flakes.
|
||||
tar cfz $TEST_ROOT/flake.tar.gz -C $TEST_ROOT flake5
|
||||
|
||||
nix build -o $TEST_ROOT/result file://$TEST_ROOT/flake.tar.gz
|
||||
|
||||
# Building with a tarball URL containing a SRI hash should also work.
|
||||
url=$(nix flake metadata --json file://$TEST_ROOT/flake.tar.gz | jq -r .url)
|
||||
[[ $url =~ sha256- ]]
|
||||
|
||||
nix build -o $TEST_ROOT/result $url
|
||||
|
||||
# Building with an incorrect SRI hash should fail.
|
||||
expectStderr 102 nix build -o $TEST_ROOT/result "file://$TEST_ROOT/flake.tar.gz?narHash=sha256-qQ2Zz4DNHViCUrp6gTS7EE4+RMqFQtUfWF2UNUtJKS0=" | grep 'NAR hash mismatch'
|
||||
|
||||
# Test --override-input.
|
||||
git -C $flake3Dir reset --hard
|
||||
nix flake lock $flake3Dir --override-input flake2/flake1 file://$TEST_ROOT/flake.tar.gz -vvvvv
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
import re
|
||||
import tarfile
|
||||
|
||||
from testlib.fixtures.nix import Nix
|
||||
from testlib.fixtures.env import ManagedEnv
|
||||
@@ -8,7 +9,7 @@ from testlib.fixtures.git import Git
|
||||
from testlib.utils import get_global_asset_pack
|
||||
from testlib.fixtures.file_helper import with_files, File, FileDeclaration, _init_files # noqa: PLC2701
|
||||
from testlib.environ import environ
|
||||
from .common import simple_flake
|
||||
from .common import simple_flake, dependent_flake
|
||||
|
||||
system = environ.get("system")
|
||||
|
||||
@@ -52,6 +53,7 @@ flake3_files = {
|
||||
"default.nix": File("{ x = 123; }"),
|
||||
}
|
||||
}
|
||||
flake5_files = {"flake5": dependent_flake()}
|
||||
|
||||
|
||||
def _make_flake_repo(
|
||||
@@ -87,6 +89,21 @@ def flake3(git: Git, env: ManagedEnv, request: pytest.FixtureRequest) -> Path:
|
||||
return _make_flake_repo("flake3", flake3_files, git, env, request)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flake5(env: ManagedEnv, request: pytest.FixtureRequest) -> Path:
|
||||
_init_files(flake5_files, env.dirs.test_root, request.path.parent, env)
|
||||
return env.dirs.test_root / "flake5"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flake5_locked_tarball(env: ManagedEnv, flake5: Path, nix: Nix) -> Path:
|
||||
nix.nix(["flake", "lock", flake5]).run().ok()
|
||||
path = env.dirs.test_root / "flake5.tar.gz"
|
||||
with tarfile.open(path, "w:gz") as tar:
|
||||
tar.add(flake5, "flake5")
|
||||
return path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def registry(nix: Nix, flake1: Path, flake2: Path, flake3: Path) -> Path:
|
||||
registry = nix.env.dirs.test_root / "registry.json"
|
||||
@@ -108,6 +125,47 @@ def registry(nix: Nix, flake1: Path, flake2: Path, flake3: Path) -> Path:
|
||||
return registry
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("registry")
|
||||
class TestBuild:
|
||||
def test_bare_repo(self, nix: Nix, flake1: Path, git: Git):
|
||||
git(None, "clone", "--bare", flake1, "bare")
|
||||
logs = nix.nix(["build", f"git+file://{nix.env.dirs.home}/bare"]).run().ok().stderr_s
|
||||
assert re.search(r"building '.*-simple.drv'", logs)
|
||||
|
||||
def test_tarball(self, nix: Nix, flake5_locked_tarball: Path):
|
||||
logs = nix.nix(["build", f"file://{flake5_locked_tarball}"]).run().ok().stderr_s
|
||||
assert "fetching tarball input" in logs
|
||||
assert re.search(r"building '.*-simple.drv'", logs)
|
||||
|
||||
def test_tarball_with_sri(self, nix: Nix, flake5_locked_tarball: Path):
|
||||
# lockfile contains absolute references to test data, hash can't be deterministic
|
||||
url = (
|
||||
nix.nix(["flake", "metadata", "--json", f"file://{flake5_locked_tarball}"])
|
||||
.run()
|
||||
.json()["url"]
|
||||
)
|
||||
assert "sha256-" in url
|
||||
|
||||
nix.clear_store()
|
||||
|
||||
logs = nix.nix(["build", url]).run().ok().stderr_s
|
||||
assert "fetching tarball input" in logs
|
||||
assert re.search(r"building '.*-simple.drv'", logs)
|
||||
|
||||
def test_tarball_bad_sri(self, nix: Nix, flake5_locked_tarball: Path):
|
||||
url = f"file://{flake5_locked_tarball}?narHash=sha256-qQ2Zz4DNHViCUrp6gTS7EE4+RMqFQtUfWF2UNUtJKS0="
|
||||
logs = nix.nix(["build", url]).run().expect(102).stderr_s
|
||||
assert "NAR hash mismatch" in logs
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("registry")
|
||||
class TestLock:
|
||||
def test_path_url(self, nix: Nix, flake5: Path):
|
||||
logs = nix.nix(["flake", "lock", f"path://{flake5}"]).run().ok().stderr_s
|
||||
assert "Added input 'flake1'" in logs
|
||||
assert f"fetching path input 'path:{flake5}" in logs
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("registry")
|
||||
class TestMetadata:
|
||||
def test_registry(self, nix: Nix):
|
||||
|
||||
Reference in New Issue
Block a user