kea-custom-hooks
FeM custom hooks libraries for Kea DHCP
Testing environment setup

Basic testing

Basic testing happens using GTest unit tests with GMock as mocking framework. CMake auto-detects if GTest is installed. However, tests must be explicitly enabled using -DWITH_TESTS=true. Afterwards, unit tests can be run using CTest.

For building and running the tests, the make target check exists, automatically building all required targets and running ctest to execute all unit tests. All test executables reside within the .../test directory within the build directory and follow the naming convention test_[COMPONENT]_runner, where COMPONENT is usually a small part of the software providing a single type of functionality, e.g. an interface for communicating with multiple Redis instances. In many cases, COMPONENT is just the name of a class for which unit tests have been written.

Advanced testing

Some tests require a more advanced system setup, since they depend on other services.

These include:

  • Redis tests (requiring a running Redis server)
  • Database tests (requiring a running database server)

Enabling and disabling advanced tests

Advanced tests are enabled by default, but can be disabled on a per-dependency basis using CMake options. The following options allow to control which tests to run:

  • WITH_HIREDIS_TESTS – Enable hiredis tests which require a running Redis server
  • WITH_PGSQL_TESTS – Enable PostgreSQL tests which require a running PostgreSQL server
  • WITH_ADMINDB_TESTS - Enable tests which require a testing AdminDB server
  • WITH_XMLRPC_TESTS - Enable tests which require spawning an XML-RPC server in a separate process

Setups for tests

Hiredis tests

  • A Redis server needs to be running on the default port.
  • The client must be able to connect without credentials.

PostgreSQL tests

  • A PostgreSQL server needs to be running somewhere.
  • A config file must be created in res/admindb-host-reservation-importer.test.conf specifying the configuration for the testing database in the localdb setting analogous to the actual configuration for admindb-host-reservation-importer
  • The database and user which are specified in the config must be present and the user needs full access on the database.

AdminDB tests

  • An AdminDB testing container needs to be running (it must not be a production instance, since tests will modify the database contents and thus taint the data stored inside!)
  • A config file must be created in res/admindb-host-reservation-importer.test.conf specifying the configuration for the testing AdminDB in the admindb setting analogous to the actual configuration for admindb-host-reservation-importer
  • The database and user which are specified in the config must be present and the user needs full access on the database. For this, create some user myuser and run ALTER ROLE myuser SUPERUSER;.

XML-RPC tests

  • Some extra tools need to be present: curl, xq, redis-cli, redis-server
  • A redis server needs to be running on the default port