blob: bf8bf5f48a720dd9101cae19b2699888581cb2e8 [file] [log] [blame]
Tomáš Pecka98ad18d2020-11-13 15:39:55 +01001/*
2 * Copyright (C) 2016-2019 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Jan Kundrát <jan.kundrat@cesnet.cz>
5 *
6*/
7
8#include "trompeloeil_doctest.h"
9#include <boost/algorithm/string/predicate.hpp>
10#include <map>
11#include <sysrepo-cpp/Session.hpp>
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010012#include "test_log_setup.h"
Tomáš Peckaba2dc312021-01-23 22:29:11 +010013#include "utils/sysrepo.h"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010014
15/** @short Return a subtree from sysrepo, compacting the XPath */
16auto dataFromSysrepo(const std::shared_ptr<sysrepo::Session>& session, const std::string& xpath)
17{
18 spdlog::get("main")->error("dataFrom {}", xpath);
19 std::map<std::string, std::string> res;
20 auto vals = session->get_items((xpath + "//*").c_str());
21 REQUIRE(!!vals);
22 for (size_t i = 0; i < vals->val_cnt(); ++i) {
23 const auto& v = vals->val(i);
24 const auto briefXPath = std::string(v->xpath()).substr(boost::algorithm::ends_with(xpath, ":*") ? xpath.size() - 1 : xpath.size());
25 res.emplace(briefXPath, v->val_to_string());
26 }
27 return res;
28}
29
Tomáš Pecka9971dcf2021-01-14 09:41:20 +010030/** @short Return a subtree from specified sysrepo's datastore, compacting the XPath*/
31auto dataFromSysrepo(const std::shared_ptr<sysrepo::Session>& session, const std::string& xpath, sr_datastore_t datastore)
32{
33 sr_datastore_t oldDatastore = session->session_get_ds();
34 session->session_switch_ds(datastore);
35
36 auto res = dataFromSysrepo(session, xpath);
37
38 session->session_switch_ds(oldDatastore);
39 return res;
40}
41
Tomáš Pecka55f64f82020-12-10 19:03:30 +010042#define TEST_SYSREPO_INIT \
43 auto srConn = std::make_shared<sysrepo::Connection>(); \
44 auto srSess = std::make_shared<sysrepo::Session>(srConn); \
45 auto srSubs = std::make_shared<sysrepo::Subscribe>(srSess);
Tomáš Pecka749af2e2021-01-14 09:52:09 +010046
47#define TEST_SYSREPO_INIT_CLIENT \
48 auto clientConn = std::make_shared<sysrepo::Connection>(); \
49 auto client = std::make_shared<sysrepo::Session>(clientConn);