mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-04-24 17:58:30 +02:00
feat: unit tests
This commit is contained in:
@@ -7,6 +7,14 @@ There is no need to do this when you have a small number of machines.
|
||||
But when you have a large number of machines, it is necessary to manage them in a fine-grained way,
|
||||
otherwise, it will be difficult to manage and maintain them.
|
||||
|
||||
## Unit Tests
|
||||
|
||||
Unit Tests for all flake outputs(only NixOS systems currently).
|
||||
|
||||
```bash
|
||||
nix eval .#unitTests --show-trace --print-build-logs --verbose
|
||||
```
|
||||
|
||||
## Overview
|
||||
|
||||
All the outputs of this flake are defined here.
|
||||
@@ -56,5 +64,3 @@ All the outputs of this flake are defined here.
|
||||
|
||||
12 directories, 28 files
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -19,12 +19,3 @@
|
||||
};
|
||||
in
|
||||
outputs
|
||||
// {
|
||||
inherit data; # for debugging purposes
|
||||
|
||||
# NixOS's unit tests.
|
||||
# unit-tests = haumea.lib.loadEvalTests {
|
||||
# src = ./tests;
|
||||
# inputs = args;
|
||||
# };
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ in
|
||||
inherit data; # for debugging purposes
|
||||
|
||||
# NixOS's unit tests.
|
||||
# unit-tests = haumea.lib.loadEvalTests {
|
||||
# src = ./tests;
|
||||
# inputs = args;
|
||||
# };
|
||||
unitTests = haumea.lib.loadEvalTests {
|
||||
src = ./tests;
|
||||
inputs = args // {inherit outputs;};
|
||||
};
|
||||
}
|
||||
|
||||
8
outputs/aarch64-linux/tests/hostname/expected.nix
Normal file
8
outputs/aarch64-linux/tests/hostname/expected.nix
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
lib,
|
||||
outputs,
|
||||
}: let
|
||||
hostsNames = builtins.attrNames outputs.nixosConfigurations;
|
||||
expected = lib.genAttrs hostsNames (name: name);
|
||||
in
|
||||
expected
|
||||
9
outputs/aarch64-linux/tests/hostname/expr.nix
Normal file
9
outputs/aarch64-linux/tests/hostname/expr.nix
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
lib,
|
||||
outputs,
|
||||
}:
|
||||
lib.genAttrs
|
||||
(builtins.attrNames outputs.nixosConfigurations)
|
||||
(
|
||||
name: outputs.nixosConfigurations.${name}.config.networking.hostName
|
||||
)
|
||||
@@ -52,6 +52,9 @@ in {
|
||||
# add attribute sets into outputs, for debugging
|
||||
debugAttrs = {inherit nixosSystems darwinSystems allSystems allSystemNames;};
|
||||
|
||||
# Unit Tests for all NixOS systems.
|
||||
unitTests = lib.lists.all (it: it.unitTests == {}) nixosSystemValues;
|
||||
|
||||
# NixOS Hosts
|
||||
nixosConfigurations =
|
||||
lib.attrsets.mergeAttrsList (map (it: it.nixosConfigurations or {}) nixosSystemValues);
|
||||
@@ -89,9 +92,6 @@ in {
|
||||
# Unit Tests, Intergraded Tests, and Pre-commit checks
|
||||
checks = forAllSystems (
|
||||
system: {
|
||||
# Unit Tests for the system
|
||||
# unit-tests = allSystems.${system}.unit-tests;
|
||||
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
|
||||
@@ -31,8 +31,8 @@ in
|
||||
inherit data; # for debugging purposes
|
||||
|
||||
# NixOS's unit tests.
|
||||
# unit-tests = haumea.lib.loadEvalTests {
|
||||
# src = ./tests;
|
||||
# inputs = args;
|
||||
# };
|
||||
unitTests = haumea.lib.loadEvalTests {
|
||||
src = ./tests;
|
||||
inputs = args // {inherit outputs;};
|
||||
};
|
||||
}
|
||||
|
||||
8
outputs/riscv64-linux/tests/hostname/expected.nix
Normal file
8
outputs/riscv64-linux/tests/hostname/expected.nix
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
lib,
|
||||
outputs,
|
||||
}: let
|
||||
hostsNames = builtins.attrNames outputs.nixosConfigurations;
|
||||
expected = lib.genAttrs hostsNames (name: name);
|
||||
in
|
||||
expected
|
||||
9
outputs/riscv64-linux/tests/hostname/expr.nix
Normal file
9
outputs/riscv64-linux/tests/hostname/expr.nix
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
lib,
|
||||
outputs,
|
||||
}:
|
||||
lib.genAttrs
|
||||
(builtins.attrNames outputs.nixosConfigurations)
|
||||
(
|
||||
name: outputs.nixosConfigurations.${name}.config.networking.hostName
|
||||
)
|
||||
@@ -19,12 +19,3 @@
|
||||
};
|
||||
in
|
||||
outputs
|
||||
// {
|
||||
inherit data; # for debugging purposes
|
||||
|
||||
# NixOS's unit tests.
|
||||
# unit-tests = haumea.lib.loadEvalTests {
|
||||
# src = ./tests;
|
||||
# inputs = args;
|
||||
# };
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ in
|
||||
inherit data; # for debugging purposes
|
||||
|
||||
# NixOS's unit tests.
|
||||
# unit-tests = haumea.lib.loadEvalTests {
|
||||
# src = ./tests;
|
||||
# inputs = args;
|
||||
# };
|
||||
unitTests = haumea.lib.loadEvalTests {
|
||||
src = ./tests;
|
||||
inputs = args // {inherit outputs;};
|
||||
};
|
||||
}
|
||||
|
||||
15
outputs/x86_64-linux/tests/home-manager/expected.nix
Normal file
15
outputs/x86_64-linux/tests/home-manager/expected.nix
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
myvars,
|
||||
lib,
|
||||
}: let
|
||||
username = myvars.username;
|
||||
hosts = [
|
||||
"ai-hyprland"
|
||||
"ai-i3"
|
||||
"shoukei-hyprland"
|
||||
"shoukei-i3"
|
||||
"ruby"
|
||||
"k3s-prod-1-master-1"
|
||||
];
|
||||
in
|
||||
lib.genAttrs hosts (_: "/home/${username}")
|
||||
20
outputs/x86_64-linux/tests/home-manager/expr.nix
Normal file
20
outputs/x86_64-linux/tests/home-manager/expr.nix
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
myvars,
|
||||
lib,
|
||||
outputs,
|
||||
}: let
|
||||
username = myvars.username;
|
||||
hosts = [
|
||||
"ai-hyprland"
|
||||
"ai-i3"
|
||||
"shoukei-hyprland"
|
||||
"shoukei-i3"
|
||||
"ruby"
|
||||
"k3s-prod-1-master-1"
|
||||
];
|
||||
in
|
||||
lib.genAttrs
|
||||
hosts
|
||||
(
|
||||
name: outputs.nixosConfigurations.${name}.config.home-manager.users.${username}.home.homeDirectory
|
||||
)
|
||||
17
outputs/x86_64-linux/tests/hostname/expected.nix
Normal file
17
outputs/x86_64-linux/tests/hostname/expected.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
lib,
|
||||
outputs,
|
||||
}: let
|
||||
specialExpected = {
|
||||
"ai-hyprland" = "ai";
|
||||
"ai-i3" = "ai";
|
||||
"shoukei-hyprland" = "shoukei";
|
||||
"shoukei-i3" = "shoukei";
|
||||
};
|
||||
specialHostNames = builtins.attrNames specialExpected;
|
||||
|
||||
otherHosts = builtins.removeAttrs outputs.nixosConfigurations specialHostNames;
|
||||
otherHostsNames = builtins.attrNames otherHosts;
|
||||
# other hosts's hostName is the same as the nixosConfigurations name
|
||||
otherExpected = lib.genAttrs otherHostsNames (name: name);
|
||||
in (specialExpected // otherExpected)
|
||||
9
outputs/x86_64-linux/tests/hostname/expr.nix
Normal file
9
outputs/x86_64-linux/tests/hostname/expr.nix
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
lib,
|
||||
outputs,
|
||||
}:
|
||||
lib.genAttrs
|
||||
(builtins.attrNames outputs.nixosConfigurations)
|
||||
(
|
||||
name: outputs.nixosConfigurations.${name}.config.networking.hostName
|
||||
)
|
||||
Reference in New Issue
Block a user