blob: 04add241c8ee02d4fecf3ad88ca771dedb96b374 [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;
16
17 SECTION("Test system-state")
18 {
19 TEST_SYSREPO_INIT_CLIENT;
20 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 }
72}