bahaghari/tests: add tests derivation for flake output

Also a schema to check if the whole test suite passes which is nice.
This commit is contained in:
Gabriel Arazas 2024-08-01 10:59:26 +08:00
parent ad32539742
commit 9c69e03395
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
3 changed files with 44 additions and 5 deletions

View File

@ -39,8 +39,15 @@
) )
); );
in eachSystem systems in eachSystem systems
(system: { (system: let
tests = branch: import ./tests { inherit branch system; };
in {
devShells.default = devShells.default =
import ./shell.nix { pkgs = import sources.nixos-stable { inherit system; }; }; import ./shell.nix { pkgs = import sources.nixos-stable { inherit system; }; };
checks = {
bahaghariLibStable = (tests "stable").libTestPkg;
bahaghariLibUnstable = (tests "unstable").libTestPkg;
};
}) // import ./default.nix { }; }) // import ./default.nix { };
} }

View File

@ -1,11 +1,27 @@
# This is the unit cases for our Nix project. # This is the unit cases for our Nix project. It should only require a nixpkgs
{ branch ? "nixos-stable" }: # instance and we'll have to make it easy to test between the unstable and
# stable version of home-manager and NixOS.
{ branch ? "stable", system ? builtins.currentSystem }:
let let
sources = import ../npins; sources = import ../npins;
pkgs = import sources.${branch} { }; pkgs = import sources."nixos-${branch}" { inherit system; };
bahaghariLib = import ./lib { inherit pkgs; };
in in
{ {
lib = import ./lib { inherit pkgs; }; lib = bahaghariLib;
libTestPkg =
pkgs.runCommand "bahaghari-lib-test"
{
testData = builtins.toJSON bahaghariLib;
passAsFile = [ "testData" ];
nativeBuildInputs = with pkgs; [
yajsv
jq
];
}
''
yajsv -s "${./lib/tests.schema.json}" "$testDataPath" && touch $out || jq . "$testDataPath"
'';
#modules = import ./modules { inherit pkgs; }; #modules = import ./modules { inherit pkgs; };
} }

View File

@ -0,0 +1,16 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "nix-lib-bahaghari Nix test object",
"type": "object",
"patternProperties": {
"^\\w+$": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 0,
"maxItems": 0
},
"required": true
}
}