From dc8facb5befbd17f2848098bbc9267c9d9f58e2d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pecka?= <tomas.pecka@cesnet.cz>
Date: Mon, 10 Mar 2025 12:08:47 +0100
Subject: [PATCH 09/20] tests: adapt to upstream breaking change in sr_get_data
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Wires

It seems that since upstream commit ba8897ce3 [1] the max_depth
parameter started behaving differently. It now behaves as the
documentation [2] states, i.e:

  Maximum depth of the selected subtrees. 0 is unlimited, 1 will not
  return any descendant nodes. If a list should be returned, its keys
  are always returned as well.

The previous behaviour was probably wrong. When reported via slack,
another fix was issued [3], so let's depend on that as well.

[1] https://github.com/sysrepo/sysrepo/commit/ba8897ce3da0bc8203d5b964851fd60fb164760d
[2] https://netopeer.liberouter.org/doc/sysrepo/devel/html/group__get__data__api.html
[3] https://github.com/sysrepo/sysrepo/commit/309b34d28cc09771cf488d04478161f684f4b8a7

Change-Id: I337dc1f1f77b9501dda29931846116050123bcad
Signed-off-by: Mattias Walström <lazzer@gmail.com>
---
 CMakeLists.txt    |  2 +-
 tests/session.cpp | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 85ff84c..fb132a2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,7 +29,7 @@ option(WITH_EXAMPLES "Build examples" ON)
 
 find_package(PkgConfig)
 pkg_check_modules(LIBYANG_CPP REQUIRED libyang-cpp>=3 IMPORTED_TARGET)
-pkg_check_modules(SYSREPO REQUIRED sysrepo>=3.4.8 IMPORTED_TARGET)
+pkg_check_modules(SYSREPO REQUIRED sysrepo>=3.6.5 IMPORTED_TARGET)
 
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
diff --git a/tests/session.cpp b/tests/session.cpp
index 2637f67..5be0d79 100644
--- a/tests/session.cpp
+++ b/tests/session.cpp
@@ -127,6 +127,13 @@ TEST_CASE("session")
             data = sess.getData("/test_module:popelnice", 1);
             REQUIRE(data);
             REQUIRE(*data->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::KeepEmptyCont) == R"({
+  "test_module:popelnice": {}
+}
+)");
+
+            data = sess.getData("/test_module:popelnice", 2);
+            REQUIRE(data);
+            REQUIRE(*data->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::KeepEmptyCont) == R"({
   "test_module:popelnice": {
     "content": {}
   }
@@ -134,7 +141,7 @@ TEST_CASE("session")
 )");
 
             // If a list should be returned, its keys are always returned as well.
-            data = sess.getData("/test_module:popelnice", 2);
+            data = sess.getData("/test_module:popelnice", 3);
             REQUIRE(data);
             REQUIRE(*data->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::KeepEmptyCont) == R"({
   "test_module:popelnice": {
@@ -152,7 +159,7 @@ TEST_CASE("session")
 }
 )");
 
-            data = sess.getData("/test_module:popelnice", 3);
+            data = sess.getData("/test_module:popelnice", 4);
             REQUIRE(data);
             REQUIRE(*data->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::KeepEmptyCont) == R"({
   "test_module:popelnice": {
-- 
2.43.0

