Testing is still very much in flux (contributions welcome!) but here’s a rough example.
default.nix
{ kubenix ? import ../../../.. }:
kubenix.evalModules.x86_64-linux {
module = { kubenix, ... }: {
imports = [ kubenix.modules.testing ];
testing = {
tests = [ ./test.nix ];
common = [{
features = [ "k8s" ];
options = {
kubernetes.version = "1.24";
};
}];
};
};
}
Where we’ve defined a test that might look like:
test.nix
{ kubenix, test, ... }: {
imports = [ kubenix.modules.test ];
test = {
name = "example";
description = "can reach deployment";
script = ''
@pytest.mark.applymanifest('${test.kubernetes.resultYAML}')
def test_nginx_deployment(kube):
"""Tests whether nginx deployment gets successfully created"""
kube.wait_for_registered(timeout=30)
deployments = kube.get_deployments()
nginx_deploy = deployments.get('nginx')
assert nginx_deploy is not None
status = nginx_deploy.status()
assert status.readyReplicas == 10
'';
};
}
Execute with
nix eval -f . config.testing.success