Skip to content

Commit

Permalink
test: add a test for packages with subpackages
Browse files Browse the repository at this point in the history
  • Loading branch information
av-gal committed Dec 18, 2024
1 parent cdd631d commit 78e9b10
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_subpackage.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
}
66 changes: 66 additions & 0 deletions tests/testpkgs/subpackage.nix
Original file line number Diff line number Diff line change
@@ -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
'';
}

0 comments on commit 78e9b10

Please sign in to comment.