mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 08:00:06 +01:00
example fix
This commit is contained in:
parent
2f2a3be87d
commit
164beed30d
4 changed files with 74 additions and 56 deletions
21
flake.nix
21
flake.nix
|
|
@ -39,12 +39,17 @@
|
||||||
in
|
in
|
||||||
lib'.evalModules (lib.recursiveUpdate
|
lib'.evalModules (lib.recursiveUpdate
|
||||||
{
|
{
|
||||||
inherit modules;
|
modules =
|
||||||
|
modules
|
||||||
|
++ [
|
||||||
|
{
|
||||||
|
_module.args = {
|
||||||
|
inherit pkgs;
|
||||||
|
name = "default";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
specialArgs = {inherit kubenix;};
|
specialArgs = {inherit kubenix;};
|
||||||
args = {
|
|
||||||
inherit pkgs;
|
|
||||||
name = "default";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
attrs');
|
attrs');
|
||||||
in {
|
in {
|
||||||
|
|
@ -74,9 +79,9 @@
|
||||||
in {
|
in {
|
||||||
# TODO: access "success" derivation with nice testing utils for nice output
|
# TODO: access "success" derivation with nice testing utils for nice output
|
||||||
nginx-example = wasSuccess (mkExamples {}).nginx-deployment.config.testing;
|
nginx-example = wasSuccess (mkExamples {}).nginx-deployment.config.testing;
|
||||||
tests-k8s-1_19 = wasSuccess (mkK8STests {k8sVersion = "1.19";});
|
#tests-k8s-1_19 = wasSuccess (mkK8STests {k8sVersion = "1.19";});
|
||||||
tests-k8s-1_20 = wasSuccess (mkK8STests {k8sVersion = "1.20";});
|
# tests-k8s-1_20 = wasSuccess (mkK8STests {k8sVersion = "1.20";});
|
||||||
tests-k8s-1_21 = wasSuccess (mkK8STests {k8sVersion = "1.21";});
|
# tests-k8s-1_21 = wasSuccess (mkK8STests {k8sVersion = "1.21";});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -64,19 +64,20 @@ with lib; let
|
||||||
config = definitions."${ref}".config;
|
config = definitions."${ref}".config;
|
||||||
});
|
});
|
||||||
|
|
||||||
submoduleWithMergeOf = ref: mergeKey: types.submodule ({name, ...}: let
|
submoduleWithMergeOf = ref: mergeKey:
|
||||||
convertName = name:
|
types.submodule ({name, ...}: let
|
||||||
if definitions."${ref}".options.${mergeKey}.type == types.int
|
convertName = name:
|
||||||
then toInt name
|
if definitions."${ref}".options.${mergeKey}.type == types.int
|
||||||
else name;
|
then toInt name
|
||||||
in {
|
else name;
|
||||||
options = definitions."${ref}".options;
|
in {
|
||||||
config =
|
options = definitions."${ref}".options;
|
||||||
definitions."${ref}".config
|
config =
|
||||||
// {
|
definitions."${ref}".config
|
||||||
${mergeKey} = mkOverride 1002 (convertName name);
|
// {
|
||||||
};
|
${mergeKey} = mkOverride 1002 (convertName name);
|
||||||
});
|
};
|
||||||
|
});
|
||||||
|
|
||||||
submoduleForDefinition = ref: resource: kind: group: version:
|
submoduleForDefinition = ref: resource: kind: group: version:
|
||||||
types.submodule ({name, ...}: {
|
types.submodule ({name, ...}: {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,23 @@
|
||||||
{ lib, config, pkgs, ... }:
|
{
|
||||||
|
lib,
|
||||||
with lib;
|
config,
|
||||||
let
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
testing = config.testing;
|
testing = config.testing;
|
||||||
cfg = testing.driver.kubetest;
|
cfg = testing.driver.kubetest;
|
||||||
|
|
||||||
kubetest = import ./kubetestdrv.nix { inherit pkgs; };
|
kubetest = import ./kubetestdrv.nix {inherit pkgs;};
|
||||||
|
|
||||||
pythonEnv = pkgs.python38.withPackages (ps: with ps; [
|
pythonEnv = pkgs.python38.withPackages (ps:
|
||||||
pytest
|
with ps;
|
||||||
kubetest
|
[
|
||||||
kubernetes
|
pytest
|
||||||
] ++ cfg.extraPackages);
|
kubetest
|
||||||
|
kubernetes
|
||||||
|
]
|
||||||
|
++ cfg.extraPackages);
|
||||||
|
|
||||||
toTestScript = t:
|
toTestScript = t:
|
||||||
if isString t.script
|
if isString t.script
|
||||||
|
|
@ -23,33 +29,34 @@ let
|
||||||
else t.script;
|
else t.script;
|
||||||
|
|
||||||
tests = let
|
tests = let
|
||||||
# make sure tests are prefixed so that alphanumerical
|
# make sure tests are prefixed so that alphanumerical
|
||||||
# sorting reproduces them in the same order as they
|
# sorting reproduces them in the same order as they
|
||||||
# have been declared in the list.
|
# have been declared in the list.
|
||||||
seive = t: t.script != null && t.enabled;
|
seive = t: t.script != null && t.enabled;
|
||||||
allEligibleTests = filter seive testing.tests;
|
allEligibleTests = filter seive testing.tests;
|
||||||
listLengthPadding = builtins.length (
|
listLengthPadding = builtins.length (
|
||||||
lib.stringToCharacters (
|
lib.stringToCharacters (
|
||||||
builtins.toString (
|
builtins.toString (
|
||||||
builtins.length allEligibleTests)));
|
builtins.length allEligibleTests
|
||||||
op =
|
)
|
||||||
(i: t: {
|
)
|
||||||
path = toTestScript t;
|
);
|
||||||
name = let
|
op = i: t: {
|
||||||
prefix = lib.fixedWidthNumber listLengthPadding i;
|
path = toTestScript t;
|
||||||
in "${prefix}_${t.name}_test.py";
|
name = let
|
||||||
});
|
prefix = lib.fixedWidthNumber listLengthPadding i;
|
||||||
in pkgs.linkFarm "${testing.name}-tests" (
|
in "${prefix}_${t.name}_test.py";
|
||||||
lib.imap0 op allEligibleTests
|
};
|
||||||
);
|
in
|
||||||
|
pkgs.linkFarm "${testing.name}-tests" (
|
||||||
|
lib.imap0 op allEligibleTests
|
||||||
|
);
|
||||||
|
|
||||||
testScript = pkgs.writeScript "test-${testing.name}.sh" ''
|
testScript = pkgs.writeScript "test-${testing.name}.sh" ''
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
${pythonEnv}/bin/pytest -p no:cacheprovider ${tests} $@
|
${pythonEnv}/bin/pytest -p no:cacheprovider ${tests} $@
|
||||||
'';
|
'';
|
||||||
|
in {
|
||||||
in
|
|
||||||
{
|
|
||||||
options.testing.driver.kubetest = {
|
options.testing.driver.kubetest = {
|
||||||
defaultHeader = mkOption {
|
defaultHeader = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
|
|
@ -62,7 +69,7 @@ in
|
||||||
extraPackages = mkOption {
|
extraPackages = mkOption {
|
||||||
type = types.listOf types.package;
|
type = types.listOf types.package;
|
||||||
description = "Extra packages to pass to tests";
|
description = "Extra packages to pass to tests";
|
||||||
default = [ ];
|
default = [];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,13 @@ with lib; let
|
||||||
|
|
||||||
# eval without checking
|
# eval without checking
|
||||||
evaled' = kubenix.evalModules {
|
evaled' = kubenix.evalModules {
|
||||||
check = false;
|
modules =
|
||||||
inherit modules;
|
modules
|
||||||
|
++ [
|
||||||
|
{
|
||||||
|
_module.args.check = false;
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
# test configuration
|
# test configuration
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue