blob: 219ce1c039331fc99bc78679461d0117955c4be2 [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
73#ifdef TEST_RPC_SYSTEM_REBOOT
74 SECTION("RPC system-restart")
75 {
76 auto sysrepo = std::make_shared<velia::system::IETFSystem>(srSess, CMAKE_CURRENT_SOURCE_DIR "/tests/system/os-release");
77
78 auto rpcInput = std::make_shared<sysrepo::Vals>(0);
79 auto res = client->rpc_send("/ietf-system:system-restart", rpcInput);
80 REQUIRE(res->val_cnt() == 0);
81 }
82#endif
Tomáš Pecka292bc9c2021-01-11 22:03:11 +010083}