From f016c3cd36dbba1fa2484eaa4c485ac8fa84d89b Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Fri, 23 May 2014 18:40:28 +0200 Subject: [PATCH] [3399] Prototype for a test that loads example config files. --- src/bin/dhcp4/tests/Makefile.am | 2 + src/bin/dhcp4/tests/configs-list.txt | 5 ++ .../dhcp4/tests/kea_controller_unittest.cc | 47 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/bin/dhcp4/tests/configs-list.txt diff --git a/src/bin/dhcp4/tests/Makefile.am b/src/bin/dhcp4/tests/Makefile.am index 95c7921a39..24977baff9 100644 --- a/src/bin/dhcp4/tests/Makefile.am +++ b/src/bin/dhcp4/tests/Makefile.am @@ -122,4 +122,6 @@ dhcp4_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la endif +noinst_DATA = configs-list.txt + noinst_PROGRAMS = $(TESTS) diff --git a/src/bin/dhcp4/tests/configs-list.txt b/src/bin/dhcp4/tests/configs-list.txt new file mode 100644 index 0000000000..f7e5587bd0 --- /dev/null +++ b/src/bin/dhcp4/tests/configs-list.txt @@ -0,0 +1,5 @@ +# This is a list of config files that the unit-tests (specifically +# JSONFileBackendTest.loadAllConfigs) is going to load. + +../../../../doc/examples/kea4/single-subnet.json +../../../../doc/examples/kea4/several-subnets.json diff --git a/src/bin/dhcp4/tests/kea_controller_unittest.cc b/src/bin/dhcp4/tests/kea_controller_unittest.cc index 9475f9b842..538016e991 100644 --- a/src/bin/dhcp4/tests/kea_controller_unittest.cc +++ b/src/bin/dhcp4/tests/kea_controller_unittest.cc @@ -234,4 +234,51 @@ TEST_F(JSONFileBackendTest, configBroken) { EXPECT_THROW(srv->init(TEST_FILE), BadValue); } +// This unit-test reads all files enumerated in configs-test.txt file, loads +// each of them and verify that they can be loaded. +// +// @todo: Unfortunately, we have this test disabled, because all loaded +// configs use memfile, which attempts to create lease file in +// /usr/local/var/bind10/kea-leases4.csv. We have couple options here: +// a) disable persistence in example configs - a very bad thing to do +// as users will forget to reenable it and then will be surprised when their +// leases disappear +// b) change configs to store lease file in /tmp. It's almost as bad as the +// previous one. Users will then be displeased when all their leases are +// wiped. (most systems wipe /tmp during boot) +// c) read each config and rewrite it on the fly, so persistence is disabled. +// This is probably the way to go, but this is a work for a dedicated ticket. +// +// Hence I'm leaving the test in, but it is disabled. +TEST_F(JSONFileBackendTest, DISABLED_loadAllConfigs) { + + // Create server first + boost::scoped_ptr srv; + ASSERT_NO_THROW( + srv.reset(new ControlledDhcpv4Srv(0)) + ); + + const char* configs_list = "configs-list.txt"; + fstream configs(configs_list, ios::in); + ASSERT_TRUE(configs.is_open()); + std::string config_name; + while (std::getline(configs, config_name)) { + + // Ignore empty and commented lines + if (config_name.empty() || config_name[0] == '#') { + continue; + } + + // Unit-tests usually do not print out anything, but in this case I + // think printing out tests configs is warranted. + std::cout << "Loading config file " << config_name << std::endl; + + try { + srv->init(config_name); + } catch (const std::exception& ex) { + ADD_FAILURE() << "Exception thrown" << ex.what() << endl; + } + } +} + } // End of anonymous namespace