From 84bd1626485400efb1bb7b737c3f4c18ce1c0da8 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Fri, 26 Jan 2024 11:25:14 +0200 Subject: [#3198] add tests for empty yang option data --- .../yang/tests/translator_option_data_unittests.cc | 184 +++++++++++++++++++++ 1 file changed, 184 insertions(+) (limited to 'src/lib') 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 -- cgit v1.2.3