blob: dd06bcc82e55f34b3542f2e084cdeeb4aeb4f3d0 [file] [log] [blame]
Tomáš Pecka292bc9c2021-01-11 22:03:11 +01001#include "trompeloeil_doctest.h"
2#include "pretty_printers.h"
Tomáš Peckaf976c5b2021-01-23 21:19:52 +01003#include "system/IETFSystem.h"
Tomáš Pecka292bc9c2021-01-11 22:03:11 +01004#include "test_log_setup.h"
5#include "test_sysrepo_helpers.h"
6#include "tests/configure.cmake.h"
7
8using namespace std::literals;
9
Tomáš Peckaf976c5b2021-01-23 21:19:52 +010010TEST_CASE("Sysrepo ietf-system")
Tomáš Pecka292bc9c2021-01-11 22:03:11 +010011{
12 trompeloeil::sequence seq1;
13
14 TEST_SYSREPO_INIT_LOGS;
15 TEST_SYSREPO_INIT;
Tomáš Pecka879a6032021-02-03 17:21:48 +010016 TEST_SYSREPO_INIT_CLIENT;
Tomáš Pecka292bc9c2021-01-11 22:03:11 +010017
18 SECTION("Test system-state")
19 {
Tomáš Pecka292bc9c2021-01-11 22:03:11 +010020 static const auto modulePrefix = "/ietf-system:system-state"s;
21
22 SECTION("Valid data")
23 {
24 std::filesystem::path file;
25 std::map<std::string, std::string> expected;
26
27 SECTION("Real data")
28 {
29 file = CMAKE_CURRENT_SOURCE_DIR "/tests/system/os-release";
30 expected = {
31 {"/clock", ""},
32 {"/platform", ""},
33 {"/platform/os-name", "CzechLight"},
34 {"/platform/os-release", "v4-105-g8294175-dirty"},
35 {"/platform/os-version", "v4-105-g8294175-dirty"},
36 };
37 }
38
39 SECTION("Missing =")
40 {
41 file = CMAKE_CURRENT_SOURCE_DIR "/tests/system/missing-equal";
42 expected = {
43 {"/clock", ""},
44 {"/platform", ""},
45 {"/platform/os-name", ""},
46 {"/platform/os-release", ""},
47 {"/platform/os-version", ""},
48 };
49 }
50
51 SECTION("Empty values")
52 {
53 file = CMAKE_CURRENT_SOURCE_DIR "/tests/system/empty-values";
54 expected = {
55 {"/clock", ""},
56 {"/platform", ""},
57 {"/platform/os-name", ""},
58 {"/platform/os-release", ""},
59 {"/platform/os-version", ""},
60 };
61 }
62
Tomáš Peckaf976c5b2021-01-23 21:19:52 +010063 auto sysrepo = std::make_shared<velia::system::IETFSystem>(srSess, file);
Tomáš Pecka292bc9c2021-01-11 22:03:11 +010064 REQUIRE(dataFromSysrepo(client, modulePrefix, SR_DS_OPERATIONAL) == expected);
65 }
66
67 SECTION("Invalid data (missing VERSION and NAME keys)")
68 {
Tomáš Peckaf976c5b2021-01-23 21:19:52 +010069 REQUIRE_THROWS_AS(std::make_shared<velia::system::IETFSystem>(srSess, CMAKE_CURRENT_SOURCE_DIR "/tests/system/missing-keys"), std::out_of_range);
Tomáš Pecka292bc9c2021-01-11 22:03:11 +010070 }
71 }
Tomáš Pecka879a6032021-02-03 17:21:48 +010072
Jan Kundrátdcd50f02021-02-18 23:28:26 +010073 SECTION("dummy values")
74 {
75 auto sys = std::make_shared<velia::system::IETFSystem>(srSess, CMAKE_CURRENT_SOURCE_DIR "/tests/system/os-release");
76 const char* xpath;
77
78 SECTION("location") {
79 xpath = "/ietf-system:system/location";
80 }
81
82 SECTION("contact") {
83 xpath = "/ietf-system:system/contact";
84 }
85
86 client->session_switch_ds(SR_DS_OPERATIONAL);
87 REQUIRE_THROWS_WITH(client->get_item(xpath), "Item not found");
88
89 client->session_switch_ds(SR_DS_RUNNING);
90 client->set_item_str(xpath, "lamparna");
91
92 REQUIRE(!!client->get_item(xpath));
93 }
94
Tomáš Pecka879a6032021-02-03 17:21:48 +010095#ifdef TEST_RPC_SYSTEM_REBOOT
96 SECTION("RPC system-restart")
97 {
98 auto sysrepo = std::make_shared<velia::system::IETFSystem>(srSess, CMAKE_CURRENT_SOURCE_DIR "/tests/system/os-release");
99
100 auto rpcInput = std::make_shared<sysrepo::Vals>(0);
101 auto res = client->rpc_send("/ietf-system:system-restart", rpcInput);
102 REQUIRE(res->val_cnt() == 0);
103 }
104#endif
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100105}