summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAndrei Pavel <andrei@isc.org>2024-01-26 10:25:14 +0100
committerAndrei Pavel <andrei@isc.org>2024-01-26 11:48:18 +0100
commit84bd1626485400efb1bb7b737c3f4c18ce1c0da8 (patch)
treed2f17f4fa3fedaaf7e2f853a3ccdf2202c12debd /src/lib
parent[#3198] add expectEqWithDiff to testutils (diff)
downloadkea-84bd1626485400efb1bb7b737c3f4c18ce1c0da8.tar.xz
kea-84bd1626485400efb1bb7b737c3f4c18ce1c0da8.zip
[#3198] add tests for empty yang option data
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/yang/tests/translator_option_data_unittests.cc184
1 files changed, 184 insertions, 0 deletions
diff --git a/src/lib/yang/tests/translator_option_data_unittests.cc b/src/lib/yang/tests/translator_option_data_unittests.cc
index 9dd0f04531..d11ce19530 100644
--- a/src/lib/yang/tests/translator_option_data_unittests.cc
+++ b/src/lib/yang/tests/translator_option_data_unittests.cc
@@ -369,4 +369,188 @@ TEST_F(TranslatorOptionDataListTestv6, optionsSameCodeAndSpace) {
expectEqWithDiff(options->get(1), got->get(3));
}
+// This test verifies that multiple options with empty option data can be
+// configured for v4.
+TEST_F(TranslatorOptionDataListTestv4, emptyData) {
+ string const xpath("/kea-dhcp4-server:config");
+
+ // Set two options with empty data.
+ ElementPtr const options(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns",
+ "csv-format": false,
+ "data": "",
+ "always-send": false,
+ "never-send": false
+ },
+ {
+ "code": 101,
+ "space": "dns",
+ "csv-format": false,
+ "data": "",
+ "always-send": false,
+ "never-send": false
+ }
+ ])"));
+ EXPECT_NO_THROW_LOG(translator_->setOptionDataList(xpath, options));
+
+ // Get them back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
+ ASSERT_TRUE(got);
+ EXPECT_EQ(2, got->size());
+
+ // Expect no "data" whatsoever. This is the same as empty "data" to the Kea DHCP server.
+ ElementPtr const expected(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns",
+ "csv-format": false,
+ "always-send": false,
+ "never-send": false
+ },
+ {
+ "code": 101,
+ "space": "dns",
+ "csv-format": false,
+ "always-send": false,
+ "never-send": false
+ }
+ ])"));
+ expectEqWithDiff(expected, got);
+}
+
+// This test verifies that multiple options with all keys and empty option data can be
+// configured for v4.
+TEST_F(TranslatorOptionDataListTestv4, emptyDataKeysOnly) {
+ string const xpath("/kea-dhcp4-server:config");
+
+ // Set two options with empty data.
+ ElementPtr const options(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns",
+ "data": ""
+ },
+ {
+ "code": 101,
+ "space": "dns",
+ "data": ""
+ }
+ ])"));
+ EXPECT_NO_THROW_LOG(translator_->setOptionDataList(xpath, options));
+
+ // Get them back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
+ ASSERT_TRUE(got);
+ EXPECT_EQ(2, got->size());
+
+ // Expect no "data" whatsoever. This is the same as empty "data" to the Kea DHCP server.
+ ElementPtr const expected(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns"
+ },
+ {
+ "code": 101,
+ "space": "dns"
+ }
+ ])"));
+ expectEqWithDiff(expected, got);
+}
+
+// This test verifies that multiple options with empty option data can be
+// configured for v6.
+TEST_F(TranslatorOptionDataListTestv6, emptyData) {
+ string const xpath("/kea-dhcp6-server:config");
+
+ // Set two options with empty data.
+ ElementPtr const options(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns",
+ "csv-format": false,
+ "data": "",
+ "always-send": false,
+ "never-send": false
+ },
+ {
+ "code": 101,
+ "space": "dns",
+ "csv-format": false,
+ "data": "",
+ "always-send": false,
+ "never-send": false
+ }
+ ])"));
+ EXPECT_NO_THROW_LOG(translator_->setOptionDataList(xpath, options));
+
+ // Get them back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
+ ASSERT_TRUE(got);
+ EXPECT_EQ(2, got->size());
+
+ // Expect no "data" whatsoever. This is the same as empty "data" to the Kea DHCP server.
+ ElementPtr const expected(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns",
+ "csv-format": false,
+ "always-send": false,
+ "never-send": false
+ },
+ {
+ "code": 101,
+ "space": "dns",
+ "csv-format": false,
+ "always-send": false,
+ "never-send": false
+ }
+ ])"));
+ expectEqWithDiff(expected, got);
+}
+
+// This test verifies that multiple options with all keys and empty option data can be
+// configured for v6.
+TEST_F(TranslatorOptionDataListTestv6, emptyDataKeysOnly) {
+ string const xpath("/kea-dhcp6-server:config");
+
+ // Set two options with empty data.
+ ElementPtr const options(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns",
+ "data": ""
+ },
+ {
+ "code": 101,
+ "space": "dns",
+ "data": ""
+ }
+ ])"));
+ EXPECT_NO_THROW_LOG(translator_->setOptionDataList(xpath, options));
+
+ // Get them back.
+ ConstElementPtr got;
+ EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
+ ASSERT_TRUE(got);
+ EXPECT_EQ(2, got->size());
+
+ // Expect no "data" whatsoever. This is the same as empty "data" to the Kea DHCP server.
+ ElementPtr const expected(Element::fromJSON(R"([
+ {
+ "code": 100,
+ "space": "dns"
+ },
+ {
+ "code": 101,
+ "space": "dns"
+ }
+ ])"));
+ expectEqWithDiff(expected, got);
+}
+
} // namespace