From 9c69e03395dca4613c1d907ae652005c2b6280c3 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 1 Aug 2024 10:59:26 +0800 Subject: [PATCH] bahaghari/tests: add tests derivation for flake output Also a schema to check if the whole test suite passes which is nice. --- subprojects/bahaghari/flake.nix | 9 ++++++- subprojects/bahaghari/tests/default.nix | 24 +++++++++++++++---- .../bahaghari/tests/lib/tests.schema.json | 16 +++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 subprojects/bahaghari/tests/lib/tests.schema.json diff --git a/subprojects/bahaghari/flake.nix b/subprojects/bahaghari/flake.nix index f9033037..6a25520c 100644 --- a/subprojects/bahaghari/flake.nix +++ b/subprojects/bahaghari/flake.nix @@ -39,8 +39,15 @@ ) ); in eachSystem systems - (system: { + (system: let + tests = branch: import ./tests { inherit branch system; }; + in { devShells.default = import ./shell.nix { pkgs = import sources.nixos-stable { inherit system; }; }; + + checks = { + bahaghariLibStable = (tests "stable").libTestPkg; + bahaghariLibUnstable = (tests "unstable").libTestPkg; + }; }) // import ./default.nix { }; } diff --git a/subprojects/bahaghari/tests/default.nix b/subprojects/bahaghari/tests/default.nix index 0b5474ed..5643ea1d 100644 --- a/subprojects/bahaghari/tests/default.nix +++ b/subprojects/bahaghari/tests/default.nix @@ -1,11 +1,27 @@ -# This is the unit cases for our Nix project. -{ branch ? "nixos-stable" }: +# This is the unit cases for our Nix project. It should only require a nixpkgs +# 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 sources = import ../npins; - pkgs = import sources.${branch} { }; + pkgs = import sources."nixos-${branch}" { inherit system; }; + bahaghariLib = import ./lib { inherit pkgs; }; 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; }; } diff --git a/subprojects/bahaghari/tests/lib/tests.schema.json b/subprojects/bahaghari/tests/lib/tests.schema.json new file mode 100644 index 00000000..e1c660f5 --- /dev/null +++ b/subprojects/bahaghari/tests/lib/tests.schema.json @@ -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 + } +}