1
1
mirror of https://github.com/divnix/digga.git synced 2024-11-26 02:23:57 +03:00

imp: remove default application of profileTests

now that we have per-host custom tests, it does not make sense anymore
to have magic lumpsum tests.

users are encouraged to use the new digga.lib.allProfilesTest standard
test and add it to a host's test like so:

`nixos.<host>.tests = [ digga.lib.allPrefilesTest ];`
This commit is contained in:
David Arnold 2021-09-05 05:06:32 -05:00 committed by Parthiv Seetharaman
parent 35e45d6a0a
commit 6267d6abf9
5 changed files with 36 additions and 42 deletions

View File

@ -12,12 +12,21 @@ packages during their [check phase][check]. All packages and their tests will
be built during CI.
## Integration Tests
All your profiles defined in suites will be tested in a NixOS VM.
All your profiles defined in suites can be tested against an individual host.
Simply use digga's pre-baked `digga.lib.allProfilesTest` like so:
```nix
{
hosts = {
Morty.tests = [ allProfilesTest ];
};
}
```
You can write integration tests for one or more NixOS VMs that can,
optionally, be networked together, and yes, it's as awesome as it sounds!
Be sure to use the `mkTest` function from Digga, `digga.lib.pkgs-lib.mkTest`
Be sure to use the `mkTest` function from Digga, `digga.lib.mkTest`
which wraps the official [testing-python][testing-python] function to ensure
that the system is setup exactly as it is for a bare DevOS system. There are
already great resources for learning how to use these tests effectively,

View File

@ -1,7 +1,12 @@
{ self, ... }:
{
{ self, inputs, ... }: let
inherit (inputs.digga.lib) allProfilesTest;
in {
hostDefaults.channelName = "nixos";
hosts = {
Morty.modules = [ ./Morty.nix ];
Morty.tests = [ allProfilesTest ];
};
importables = rec { suites = rec {
base = [ ];
};};
}

View File

@ -113,7 +113,7 @@
inherit (flake-utils-plus.inputs.flake-utils.lib) defaultSystems eachSystem eachDefaultSystem filterPackages;
inherit (flake-utils-plus.lib) exportModules exportOverlays exportPackages;
inherit mkFlake;
inherit (tests) mkTest;
inherit (tests) mkTest allProfilesTest;
inherit (importers) flattenTree rakeLeaves importOverlays importModules importHosts;
inherit (generators) mkDeployNodes mkHomeConfigurations;

View File

@ -112,14 +112,6 @@ in
systemSieve = _: host: host.config.nixpkgs.system == system;
hostConfigsOnThisSystem = lib.filterAttrs systemSieve config.self.nixosConfigurations;
suitesSieve = n: host:
lib.warnIf (host.config.lib.specialArgs.suites == null) ''
'${n}' will only be tested against all profiles if 'importables.suites'
are used to declare your profiles.
''
host.config.lib.specialArgs.suites != null;
hostConfigsOnThisSystemWithSuites = lib.filterAttrs suitesSieve hostConfigsOnThisSystem;
createCustomTestOp = n: host: test:
lib.warnIf (!(test ? name)) ''
'${n}' has a test without a name. To distinguish tests in the flake output
@ -136,23 +128,12 @@ in
in
builtins.listToAttrs (map op config.nixos.hosts.${n}.tests);
createAllProfilesTestOp = n: host: {
name = "allProfilesTestFor-${n}";
value = tests.profilesTest host;
};
profilesTests =
if (hostConfigsOnThisSystemWithSuites != [ ])
then lib.mapAttrs' createAllProfilesTestOp hostConfigsOnThisSystemWithSuites
else { };
customTests =
if (hostConfigsOnThisSystem != [ ])
then lib.foldl (a: b: a // b) { } (lib.attrValues (lib.mapAttrs createCustomTestsOp hostConfigsOnThisSystem))
else { };
in
(profilesTests // customTests)
in customTests
else { }
)
;

View File

@ -27,9 +27,8 @@ let
in
nixosTesting.makeTest (maybeCallTest pkgs (maybeImport test));
profilesTest = host:
mkTest host {
name = "profiles";
allProfilesTest = {
name = "allProfiles";
machine = { suites ? null, ... }: {
imports =
@ -42,8 +41,8 @@ let
};
testScript = ''
${host.config.networking.hostName}.systemctl("is-system-running --wait")
machines[0].systemctl("is-system-running --wait")
'';
};
in
{ inherit mkTest profilesTest; }
{ inherit mkTest allProfilesTest; }