From 0f1df5e447fb4b88ee80261b20d3cf23a5161155 Mon Sep 17 00:00:00 2001
From: Gabriel Arazas <foodogsquared@foodogsquared.one>
Date: Sat, 13 Jul 2024 17:00:06 +0800
Subject: [PATCH] wrapper-manager-fds/tests: init derivation for tests

This is to make checking with flakes a bit easier. Though, there are
much better ways to integrate this even with just the nix-command
experimental feature.
---
 .../wrapper-manager-fds/tests/default.nix      | 18 ++++++++++++++----
 .../tests/lib/tests.schema.json                | 16 ++++++++++++++++
 .../wrapper-manager-fds/tests/lib/utils.nix    |  8 ++++----
 3 files changed, 34 insertions(+), 8 deletions(-)
 create mode 100644 subprojects/wrapper-manager-fds/tests/lib/tests.schema.json

diff --git a/subprojects/wrapper-manager-fds/tests/default.nix b/subprojects/wrapper-manager-fds/tests/default.nix
index 539c82d7..bea84791 100644
--- a/subprojects/wrapper-manager-fds/tests/default.nix
+++ b/subprojects/wrapper-manager-fds/tests/default.nix
@@ -1,9 +1,19 @@
-{ branch ? "nixos-stable" }:
-
 let
   sources = import ../npins;
-  pkgs = import sources.${branch} { };
+in
+{ pkgs ? import sources.nixos-unstable { } }:
+
+let
+  lib = import ./lib { inherit pkgs; };
 in
 {
-  lib = import ./lib { inherit pkgs; };
+  inherit lib;
+  libTestPkg =
+    pkgs.runCommand "wrapper-manager-fds-lib-test" {
+      testData = builtins.toJSON lib;
+      passAsFile = [ "testData" ];
+      nativeBuildInputs = with pkgs; [ yajsv jq ];
+    } ''
+      yajsv -s "${./lib/tests.schema.json}" "$testDataPath" && touch $out || jq . "$testDataPath"
+    '';
 }
diff --git a/subprojects/wrapper-manager-fds/tests/lib/tests.schema.json b/subprojects/wrapper-manager-fds/tests/lib/tests.schema.json
new file mode 100644
index 00000000..d1e97e1b
--- /dev/null
+++ b/subprojects/wrapper-manager-fds/tests/lib/tests.schema.json
@@ -0,0 +1,16 @@
+{
+  "$schema": "https://json-schema.org/draft/2020-12/schema",
+  "title": "wrapper-manager-fds Nix test object",
+  "type": "object",
+  "patternProperties": {
+    "^\\w+$": {
+      "type": "array",
+      "items": {
+        "type": "string"
+      },
+      "minItems": 0,
+      "maxItems": 0
+    },
+    "required": true
+  }
+}
diff --git a/subprojects/wrapper-manager-fds/tests/lib/utils.nix b/subprojects/wrapper-manager-fds/tests/lib/utils.nix
index 8f784940..76d7f97b 100644
--- a/subprojects/wrapper-manager-fds/tests/lib/utils.nix
+++ b/subprojects/wrapper-manager-fds/tests/lib/utils.nix
@@ -3,22 +3,22 @@
 lib.runTests {
   testsUtilsGetBin = {
     expr = self.utils.getBin [
-      ../modules
+      ../../lib
       ../../modules
     ];
     expected = [
-      (lib.getBin ../modules)
+      (lib.getBin ../../lib)
       (lib.getBin ../../modules)
     ];
   };
 
   testsUtilsGetLibexec = {
     expr = self.utils.getLibexec [
-      ../modules
+      ../../lib
       ../../modules
     ];
     expected = [
-      "${../modules}/libexec"
+      "${../../lib}/libexec"
       "${../../modules}/libexec"
     ];
   };