Skip to content

Testing

To ensure no regression in KubeHound, 2 kinds of tests are in place:

  • classic unit test: can be identify with the xxx_test.go files in the source code
  • system tests: end to end test where we run full ingestion from different scenario to simulate all use cases against a real cluster.

Requirements test

Unit Testing

The full suite of unit tests can be run locally via:

make test

System Testing

The repository includes a suite of system tests that will do the following:

  • create a local kubernetes cluster
  • collect kubernetes API data from the cluster
  • run KubeHound using the file collector to create a working graph database
  • query the graph database to ensure all expected vertices and edges have been created correctly

The cluster setup and running instances can be found under test/setup

If you need to manually access the system test environment with kubectl and other commands, you'll need to set (assuming you are at the root dir):

cd test/setup/ && export KUBECONFIG=$(pwd)/.kube-config

Environment variable:

  • DD_API_KEY (optional): set to the datadog API key used to submit metrics and other observability data (see datadog section)

Setup

Setup the test kind cluster (you only need to do this once!) via:

make local-cluster-deploy

Running the system tests

Then run the system tests via:

make system-test

Cleanup

To cleanup the environment you can destroy the cluster via:

make local-cluster-destroy

Note

if you are running on Linux but you dont want to run sudo for kind and docker command, you can overwrite this behavior by editing the following var in test/setup/.config:

* `DOCKER_CMD="docker"` for docker command
* `KIND_CMD="kind"` for kind command

CI Testing

System tests will be run in CI via the system-test github action