feat: run test for all k8s versions

This commit is contained in:
Jaka Hudoklin 2019-02-16 14:02:13 +01:00
parent fde2d5557c
commit 0d68a401f0
No known key found for this signature in database
GPG key ID: 916062A1C4748647
3 changed files with 25 additions and 3 deletions

View file

@ -1,17 +1,24 @@
{ pkgs ? import <nixpkgs> {} { pkgs ? import <nixpkgs> {}
, kubenix ? import ../. {inherit pkgs;} , kubenix ? import ../. {inherit pkgs;}
, lib ? kubenix.lib , lib ? kubenix.lib
, k8sVersions ? ["1.7" "1.8" "1.9" "1.10" "1.11" "1.12" "1.13"]
# whether any testing error should throw an error # whether any testing error should throw an error
, throwError ? true }: , throwError ? true }:
with lib; with lib;
(evalModules { listToAttrs (map (version: let
version' = replaceStrings ["."] ["_"] version;
in nameValuePair "v${version'}" (evalModules {
modules = [ modules = [
./modules/testing.nix ./modules/testing.nix
{ {
imports = [kubenix.k8s kubenix.submodules];
kubernetes.version = version;
testing.throwError = throwError; testing.throwError = throwError;
testing.tests = [ testing.tests = [
./k8s/simple.nix ./k8s/simple.nix
@ -20,6 +27,10 @@ with lib;
./k8s/1.13/crd.nix ./k8s/1.13/crd.nix
./submodules/simple.nix ./submodules/simple.nix
]; ];
testing.defaults = ({kubenix, ...}: {
imports = [kubenix.k8s];
kubernetes.version = version;
});
} }
]; ];
args = { args = {
@ -28,4 +39,4 @@ with lib;
specialArgs = { specialArgs = {
inherit kubenix; inherit kubenix;
}; };
}).config.testing.result }).config.testing.result) k8sVersions)

View file

@ -12,6 +12,7 @@ in {
test = { test = {
name = "k8s/crd"; name = "k8s/crd";
description = "Simple test tesing CRD"; description = "Simple test tesing CRD";
enable = builtins.compareVersions config.kubernetes.version "1.8" >= 0;
assertions = [{ assertions = [{
message = "should have group set"; message = "should have group set";
assertion = cfg.spec.group == "stable.example.com"; assertion = cfg.spec.group == "stable.example.com";

View file

@ -4,6 +4,7 @@ with lib;
let let
cfg = config.testing; cfg = config.testing;
parentConfig = config;
in { in {
options = { options = {
testing.throwError = mkOption { testing.throwError = mkOption {
@ -12,13 +13,22 @@ in {
default = true; default = true;
}; };
testing.defaults = mkOption {
description = "Testing defaults";
type = types.coercedTo types.unspecified (value: [value]) (types.listOf types.unspecified);
example = literalExample ''{config, ...}: {
kubernetes.version = config.kubernetes.version;
}'';
default = [];
};
testing.tests = mkOption { testing.tests = mkOption {
description = "Attribute set of test cases"; description = "Attribute set of test cases";
default = []; default = [];
type = types.listOf (types.coercedTo types.path (module: {inherit module;}) (types.submodule ({config, ...}: let type = types.listOf (types.coercedTo types.path (module: {inherit module;}) (types.submodule ({config, ...}: let
modules = [config.module ./test.nix { modules = [config.module ./test.nix {
config._module.args.test = config; config._module.args.test = config;
}]; }] ++ cfg.defaults;
test = (kubenix.evalKubernetesModules { test = (kubenix.evalKubernetesModules {
check = false; check = false;