From 78e9b10d47b41e9ba1360d385f940db4aebc036c Mon Sep 17 00:00:00 2001 From: Alex Galvin Date: Wed, 18 Dec 2024 01:12:19 -0500 Subject: [PATCH] test: add a test for packages with subpackages --- tests/test_subpackage.py | 41 ++++++++++++++++++++++ tests/testpkgs/default.nix | 1 + tests/testpkgs/subpackage.nix | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 tests/test_subpackage.py create mode 100644 tests/testpkgs/subpackage.nix diff --git a/tests/test_subpackage.py b/tests/test_subpackage.py new file mode 100644 index 0000000..8c2e4de --- /dev/null +++ b/tests/test_subpackage.py @@ -0,0 +1,41 @@ +import subprocess +from pathlib import Path + +import conftest + +from nix_update.options import Options +from nix_update.update import update + + +def test_update(helpers: conftest.Helpers) -> None: + with helpers.testpkgs() as path: + opts = Options(attribute="subpackage", subpackages=["autobrr-web"], import_path=str(path)) + update(opts) + + def get_attr(attr: str) -> str: + return subprocess.run( + [ + "nix", + "eval", + "--raw", + "--extra-experimental-features", + "nix-command", + "-f", + path, + attr, + ], + text=True, + stdout=subprocess.PIPE, + ).stdout.strip() + + subpackage_hash = get_attr("subpackage.autobrr-web.pnpmDeps.outputHash") + assert subpackage_hash != "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" + + src_hash = get_attr("subpackage.src.outputHash") + assert src_hash != "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" + + gomodules_hash = get_attr("subpackage.goModules.outputHash") + assert src_hash != "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" + + version = get_attr("subpackage.version") + assert tuple(map(int, version.split("."))) >= (1, 53, 0) diff --git a/tests/testpkgs/default.nix b/tests/testpkgs/default.nix index 96dd0e5..b5a4154 100644 --- a/tests/testpkgs/default.nix +++ b/tests/testpkgs/default.nix @@ -32,4 +32,5 @@ mix = pkgs.callPackage ./mix.nix { }; set = pkgs.callPackage ./set.nix { }; let-bound-version = pkgs.callPackage ./let-bound-version.nix { }; + subpackage = pkgs.callPackage ./subpackage.nix { }; } diff --git a/tests/testpkgs/subpackage.nix b/tests/testpkgs/subpackage.nix new file mode 100644 index 0000000..69b4657 --- /dev/null +++ b/tests/testpkgs/subpackage.nix @@ -0,0 +1,66 @@ +{ + lib, + buildGoModule, + fetchFromGitHub, + stdenvNoCC, + nix-update-script, + nodejs, + pnpm_9, + typescript, +}: + +let + pname = "autobrr"; + version = "1.53.0"; + src = fetchFromGitHub { + owner = "autobrr"; + repo = "autobrr"; + rev = "v${version}"; + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + }; + + autobrr-web = stdenvNoCC.mkDerivation { + pname = "${pname}-web"; + inherit src version; + + nativeBuildInputs = [ + nodejs + pnpm_9.configHook + typescript + ]; + + sourceRoot = "${src.name}/web"; + + pnpmDeps = pnpm_9.fetchDeps { + inherit (autobrr-web) + pname + version + src + sourceRoot + ; + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + }; + + postBuild = '' + pnpm run build + ''; + + installPhase = '' + cp -r dist $out + ''; + }; +in +buildGoModule rec { + inherit + autobrr-web + pname + version + src + ; + + vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + + preBuild = '' + cp -r ${autobrr-web}/* web/dist + ''; +}