2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[#3931] fixed unit tests

This commit is contained in:
Razvan Becheriu 2025-07-14 16:20:00 +03:00 committed by Andrei Pavel
parent d6cda7da63
commit 3797f803d6
No known key found for this signature in database
GPG Key ID: D4E804481939CB21
2 changed files with 25 additions and 7 deletions

View File

@ -19,7 +19,7 @@ support for a YANG/NETCONF interface with the :iscman:`kea-netconf` agent.
Installing NETCONF Installing NETCONF
------------------ ------------------
To get its NETCONF capabilities, Kea requires the v2 versions of libyang and To get its NETCONF capabilities, Kea requires the v3 versions of libyang and
Sysrepo. The specific versions that have been thoroughly tested with Kea are: Sysrepo. The specific versions that have been thoroughly tested with Kea are:
* libyang v3.12.2 (da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8) * libyang v3.12.2 (da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8)

View File

@ -35,7 +35,9 @@ private:
void cleanUp() { void cleanUp() {
Session session(sysrepo::Connection{}.sessionStart()); Session session(sysrepo::Connection{}.sessionStart());
session.switchDatastore(sysrepo::Datastore::Candidate); session.switchDatastore(sysrepo::Datastore::Candidate);
session.deleteItem("/keatest-module:container"); if (session.getData("/keatest-module:container/list")) {
session.deleteItem("/keatest-module:container/list");
}
session.deleteItem("/keatest-module:kernel-modules"); session.deleteItem("/keatest-module:kernel-modules");
session.deleteItem("/keatest-module:list"); session.deleteItem("/keatest-module:list");
session.deleteItem("/keatest-module:main"); session.deleteItem("/keatest-module:main");
@ -367,7 +369,9 @@ TEST_F(TranslatorTest, deleteItem) {
Translator translator(Connection{}.sessionStart(), "keatest-module"); Translator translator(Connection{}.sessionStart(), "keatest-module");
// Missing schema node // Missing schema node
EXPECT_NO_THROW_LOG(translator.deleteItem("/keatest-module:main/no_such_node")); EXPECT_THROW_MSG(translator.deleteItem("/keatest-module:main/no_such_node"), NetconfError,
"deleting item at '/keatest-module:main/no_such_node': Session::getData: "
"Couldn't get '/keatest-module:main/no_such_node': SR_ERR_NOT_FOUND");
// Existing schema node, but no data // Existing schema node, but no data
xpath = "/keatest-module:main/string"; xpath = "/keatest-module:main/string";
@ -802,7 +806,8 @@ TEST_F(TranslatorTest, setItem) {
EXPECT_THROW_MSG(translator->setItem(xpath, element, LeafBaseType::String), NetconfError, EXPECT_THROW_MSG(translator->setItem(xpath, element, LeafBaseType::String), NetconfError,
"setting item '\"str\"' at '" + xpath + "setting item '\"str\"' at '" + xpath +
"': Session::setItem: Couldn't set " "': Session::setItem: Couldn't set "
"'/keatest-module:main/no_such_node' to 'str': SR_ERR_INVAL_ARG"); "'/keatest-module:main/no_such_node' to 'str': SR_ERR_LY\n Not found node "
"\"no_such_node\" in path. (path \"/keatest-module:main\") (SR_ERR_LY)");
// Bad type. // Bad type.
xpath = "/keatest-module:main/string"; xpath = "/keatest-module:main/string";
@ -858,9 +863,22 @@ TEST_F(TranslatorTest, container) {
"getting node of type 1 not supported, xpath is '/keatest-module:container'"); "getting node of type 1 not supported, xpath is '/keatest-module:container'");
EXPECT_FALSE(element); EXPECT_FALSE(element);
element.reset(); element.reset();
EXPECT_NO_THROW_LOG( optional<DataNode> const& container(translator.findXPath("/keatest-module:container"));
element = translator.getItemFromAbsoluteXpath("/keatest-module:container[key1='key1'][key2='key2']")); try {
EXPECT_FALSE(element); libyang::Set<libyang::DataNode> const& nodes((*container).findXPath("/keatest-module:container/list"));
element = isc::data::Element::createList();
for (libyang::DataNode const& i : nodes) {
ElementPtr result = Element::createMap();
translator.getMandatoryLeaf(result, i, "key1");
translator.getMandatoryLeaf(result, i, "key2");
translator.checkAndGetLeaf(result, i, "leaf");
element->add(result);
}
} catch (libyang::Error const& ex) {
ADD_FAILURE() << "failed to retrieve keatest-module:container/list[key1='key1][key2='key2']. error: " << ex.what();
}
ASSERT_TRUE(element);
ASSERT_EQ("[ { \"key1\": \"key1\", \"key2\": \"key2\", \"leaf\": \"Leaf value\" } ]", element->str());
} }
// Test YANG list retrieval. // Test YANG list retrieval.