fixup tests

This commit is contained in:
David Arnold 2021-05-28 20:26:17 -05:00 committed by "David Arnold"
parent bf231d19fa
commit 39badb2084
No known key found for this signature in database
GPG key ID: 6D6A936E69C59D08
34 changed files with 88 additions and 110 deletions

View file

@ -1,5 +1,9 @@
{ kubenix ? (import ./.. { }).default }: { system ? builtins.currentSystem
, evalModules ? (import ../. { }).evalModules.${system}
}:
{ registry ? "docker.io/gatehub" }:
{ {
nginx-deployment = import ./nginx-deployment { inherit kubenix; }; nginx-deployment = import ./nginx-deployment { inherit evalModules registry; };
} }

View file

@ -1,30 +1,36 @@
{ kubenix ? import ../.. { }, registry ? "docker.io/gatehub" }: { evalModules, registry }:
with kubenix.lib; let
rec {
# evaluated configuration # evaluated configuration
config = (kubenix.evalModules { config = (evalModules {
modules = [ modules = [
({ kubenix, ... }: { imports = [ kubenix.modules.testing ]; })
./module.nix ./module.nix
{ docker.registry.url = registry; } { docker.registry.url = registry; }
kubenix.modules.testing
{ {
testing.tests = [ ./test.nix ]; testing.tests = [ ./test.nix ];
testing.defaults = ({ lib, ... }: with lib; { testing.docker.registryUrl = "";
docker.registry.url = mkForce "";
kubernetes.version = config.kubernetes.version;
});
} }
]; ];
}).config; }).config;
# e2e test in
test = config.testing.result; {
inherit config;
# config checks
checks = config.testing.success;
# TODO: e2e test
# test = config.testing.result;
# nixos test script for running the test # nixos test script for running the test
test-script = config.testing.testsByName.nginx-deployment.test; test-script = config.testing.testsByName.nginx-deployment.script;
# genreated kubernetes List object # genreated kubernetes List object
generated = config.kubernetes.generated; generated = config.kubernetes.generated;

View file

@ -21,9 +21,39 @@
config = { allowUnsupportedSystem = true; }; config = { allowUnsupportedSystem = true; };
}; };
lib = pkgs.lib;
kubenix = {
lib = import ./lib { inherit lib pkgs; };
evalModules = self.evalModules.${system};
modules = self.modules;
};
# evalModules with same interface as lib.evalModules and kubenix as
# special argument
evalModules = attrs@{ module ? null, modules ? [ module ], ... }:
let
lib' = lib.extend (lib: self: import ./lib/upstreamables.nix { inherit lib pkgs; });
attrs' = builtins.removeAttrs attrs [ "module" ];
in
lib'.evalModules (lib.recursiveUpdate
{
inherit modules;
specialArgs = { inherit kubenix; };
args = {
inherit pkgs;
name = "default";
};
}
attrs');
in in
{ {
inherit evalModules;
jobs = import ./jobs { inherit pkgs; };
devShell = with pkgs; devshell.mkShell devShell = with pkgs; devshell.mkShell
{ imports = [ (devshell.importTOML ./devshell.toml) ]; }; { imports = [ (devshell.importTOML ./devshell.toml) ]; };
@ -31,9 +61,22 @@
inherit (pkgs) kubernetes kubectl; inherit (pkgs) kubernetes kubectl;
}; };
defaultPackage = pkgs.kubenix; checks = let
wasSuccess = suite:
jobs = import ./jobs { inherit pkgs; }; if suite.success == true
then pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-succeeded" {} "echo success > $out"
else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" {} "exit 1";
mkExamples = attrs: (import ./examples { inherit evalModules; })
({ registry = "docker.io/gatehub"; } // attrs);
mkK8STests = attrs: (import ./tests { inherit evalModules; })
({ registry = "docker.io/gatehub"; } // attrs);
in {
# TODO: access "success" derivation with nice testing utils for nice output
nginx-example = wasSuccess (mkExamples { }).nginx-deployment.config.testing;
tests-k8s-1_19 = wasSuccess (mkK8STests { k8sVersion = "1.19"; });
tests-k8s-1_20 = wasSuccess (mkK8STests { k8sVersion = "1.20"; });
tests-k8s-1_21 = wasSuccess (mkK8STests { k8sVersion = "1.21"; });
};
} }
)) ))
@ -41,9 +84,9 @@
// //
{ {
modules = import ./src/modules; modules = import ./modules;
overlay = final: prev: { overlay = final: prev: {
kubenix = prev.callPackage ./src/kubenix.nix { }; kubenix.evalModules = self.evalModules.${prev.system};
# up to date versions of their nixpkgs equivalents # up to date versions of their nixpkgs equivalents
kubernetes = prev.callPackage ./pkgs/applications/networking/cluster/kubernetes kubernetes = prev.callPackage ./pkgs/applications/networking/cluster/kubernetes
{ }; { };

View file

@ -1,33 +0,0 @@
let
fetch = import ./lib/compat.nix;
in
{ pkgs ? import (fetch "nixpkgs") { }
, lib ? pkgs.lib
, throwError ? true
}:
with lib;
let
kubenix = import ./. { inherit pkgs; };
lib = kubenix.lib;
runK8STests = k8sVersion: import ./tests {
inherit pkgs lib kubenix k8sVersion throwError nixosPath;
};
in
rec {
tests = {
k8s-1_19 = runK8STests "1.19";
k8s-1_20 = runK8STests "1.20";
k8s-1_21 = runK8STests "1.21";
};
test-check =
if !(all (test: test.success) (attrValues tests))
then throw "tests failed"
else true;
examples = import ./examples { };
}

View file

@ -1,37 +0,0 @@
{ pkgs, lib }:
let
kubenix = {
inherit evalModules;
lib = import ./lib { inherit lib pkgs; };
modules = import ./modules;
};
defaultSpecialArgs = {
inherit kubenix;
};
# evalModules with same interface as lib.evalModules and kubenix as
# special argument
evalModules =
{ module ? null
, modules ? [ module ]
, specialArgs ? defaultSpecialArgs
, ...
}@attrs:
let
lib' = lib.extend (lib: self: import ./lib/upstreamables.nix { inherit lib pkgs; });
attrs' = builtins.removeAttrs attrs [ "module" ];
in
lib'.evalModules (lib.recursiveUpdate
{
inherit specialArgs modules;
args = {
inherit pkgs;
name = "default";
};
}
attrs');
in
kubenix

View file

@ -1,22 +1,21 @@
{ pkgs ? import <nixpkgs> { } { system ? builtins.currentSystem
, lib ? pkgs.lib , evalModules ? (import ../. { }).evalModules.${system}
, kubenix ? (import ../. { }).default }:
, k8sVersion ? "1.21" { k8sVersion ? "1.21"
, registryUrl ? throw "Registry url not defined" , registry ? throw "Registry url not defined"
, throwError ? true # whether any testing error should throw an error , throwError ? true # whether any testing error should throw an error
, enabledTests ? null , enabledTests ? null
}: }:
with lib;
let let
images = pkgs.callPackage ./images.nix { }; config = (evalModules {
config = (kubenix.evalModules {
modules = [ modules = [
kubenix.modules.testing
{ ({ kubenix, ... }: { imports = [ kubenix.modules.testing ]; })
({ pkgs, ... }: {
testing = { testing = {
name = "kubenix-${k8sVersion}"; name = "kubenix-${k8sVersion}";
throwError = throwError; throwError = throwError;
@ -38,9 +37,9 @@ let
./submodules/passthru.nix ./submodules/passthru.nix
]; ];
args = { args = {
inherit images; images = pkgs.callPackage ./images.nix { };
}; };
docker.registryUrl = registryUrl; docker.registryUrl = registry;
defaults = [ defaults = [
{ {
features = [ "k8s" ]; features = [ "k8s" ];
@ -50,14 +49,10 @@ let
} }
]; ];
}; };
} })
]; ];
args = {
inherit pkgs;
};
specialArgs = {
inherit kubenix;
};
}).config; }).config;
in in
pkgs.recurseIntoAttrs config.testing config.testing // { recurseForDerivations = true; }