From: Francis Dupont Date: Sat, 20 Jul 2019 15:35:47 +0000 (+0200) Subject: [732-set-with-incorrect-tag-new-exception] Added a new unit test (for v4 and v6)... X-Git-Tag: Kea-1.6.1~10^2~107^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82f34e60363eec72a117939a5526bdb1ececb53c;p=thirdparty%2Fkea.git [732-set-with-incorrect-tag-new-exception] Added a new unit test (for v4 and v6) to check NullKeyError message --- diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc index 81b089389f..cf104ceb70 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc @@ -1058,6 +1058,25 @@ TEST_F(MySqlConfigBackendDHCPv4Test, getModifiedGlobalParameters4) { EXPECT_EQ(1, parameters.size()); } +// Test that the NullKeyError message is correctly updated. +TEST_F(MySqlConfigBackendDHCPv4Test, nullKeyError) { + // Create a global parameter (it should work with any object type). + StampedValuePtr global_parameter = StampedValue::create("global", "value"); + + // Try to insert it and associate with non-existing server. + std::string msg; + try { + cbptr_->createUpdateGlobalParameter4(ServerSelector::ONE("server1"), + global_parameter); + msg = "got no exception"; + } catch (const NullKeyError& ex) { + msg = ex.what(); + } catch (const std::exception&) { + msg = "got another exception"; + } + EXPECT_EQ("server 'server1' does not exist", msg); +} + // Test that ceateUpdateSubnet4 throws appropriate exceptions for various // server selectors. TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateSubnet4Selectors) { diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc index 3ae977a78d..80975f3b86 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc @@ -1093,6 +1093,25 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getModifiedGlobalParameters6) { EXPECT_EQ(1, parameters.size()); } +// Test that the NullKeyError message is correctly updated. +TEST_F(MySqlConfigBackendDHCPv6Test, nullKeyError) { + // Create a global parameter (it should work with any object type). + StampedValuePtr global_parameter = StampedValue::create("global", "value"); + + // Try to insert it and associate with non-existing server. + std::string msg; + try { + cbptr_->createUpdateGlobalParameter6(ServerSelector::ONE("server1"), + global_parameter); + msg = "got no exception"; + } catch (const NullKeyError& ex) { + msg = ex.what(); + } catch (const std::exception&) { + msg = "got another exception"; + } + EXPECT_EQ("server 'server1' does not exist", msg); +} + // Test that ceateUpdateSubnet6 throws appropriate exceptions for various // server selectors. TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateSubnet6Selectors) {