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;
rec {
let
# evaluated configuration
config = (kubenix.evalModules {
config = (evalModules {
modules = [
({ kubenix, ... }: { imports = [ kubenix.modules.testing ]; })
./module.nix
{ docker.registry.url = registry; }
kubenix.modules.testing
{
testing.tests = [ ./test.nix ];
testing.defaults = ({ lib, ... }: with lib; {
docker.registry.url = mkForce "";
kubernetes.version = config.kubernetes.version;
});
testing.docker.registryUrl = "";
}
];
}).config;
# e2e test
test = config.testing.result;
in
{
inherit config;
# config checks
checks = config.testing.success;
# TODO: e2e test
# test = config.testing.result;
# 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
generated = config.kubernetes.generated;

View file

@ -21,9 +21,39 @@
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
{
inherit evalModules;
jobs = import ./jobs { inherit pkgs; };
devShell = with pkgs; devshell.mkShell
{ imports = [ (devshell.importTOML ./devshell.toml) ]; };
@ -31,9 +61,22 @@
inherit (pkgs) kubernetes kubectl;
};
defaultPackage = pkgs.kubenix;
jobs = import ./jobs { inherit pkgs; };
checks = let
wasSuccess = suite:
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: {
kubenix = prev.callPackage ./src/kubenix.nix { };
kubenix.evalModules = self.evalModules.${prev.system};
# up to date versions of their nixpkgs equivalents
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> { }
, lib ? pkgs.lib
, kubenix ? (import ../. { }).default
{ system ? builtins.currentSystem
, evalModules ? (import ../. { }).evalModules.${system}
}:
, k8sVersion ? "1.21"
, registryUrl ? throw "Registry url not defined"
{ k8sVersion ? "1.21"
, registry ? throw "Registry url not defined"
, throwError ? true # whether any testing error should throw an error
, enabledTests ? null
}:
with lib;
let
images = pkgs.callPackage ./images.nix { };
config = (evalModules {
config = (kubenix.evalModules {
modules = [
kubenix.modules.testing
{
({ kubenix, ... }: { imports = [ kubenix.modules.testing ]; })
({ pkgs, ... }: {
testing = {
name = "kubenix-${k8sVersion}";
throwError = throwError;
@ -38,9 +37,9 @@ let
./submodules/passthru.nix
];
args = {
inherit images;
images = pkgs.callPackage ./images.nix { };
};
docker.registryUrl = registryUrl;
docker.registryUrl = registry;
defaults = [
{
features = [ "k8s" ];
@ -50,14 +49,10 @@ let
}
];
};
}
})
];
args = {
inherit pkgs;
};
specialArgs = {
inherit kubenix;
};
}).config;
in
pkgs.recurseIntoAttrs config.testing
config.testing // { recurseForDerivations = true; }