Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 1 | #include "trompeloeil_doctest.h" |
| 2 | #include "pretty_printers.h" |
Tomáš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 3 | #include "system/IETFSystem.h" |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 4 | #include "test_log_setup.h" |
| 5 | #include "test_sysrepo_helpers.h" |
| 6 | #include "tests/configure.cmake.h" |
| 7 | |
| 8 | using namespace std::literals; |
| 9 | |
Tomáš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 10 | TEST_CASE("Sysrepo ietf-system") |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 11 | { |
| 12 | trompeloeil::sequence seq1; |
| 13 | |
| 14 | TEST_SYSREPO_INIT_LOGS; |
| 15 | TEST_SYSREPO_INIT; |
Tomáš Pecka | 879a603 | 2021-02-03 17:21:48 +0100 | [diff] [blame^] | 16 | TEST_SYSREPO_INIT_CLIENT; |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 17 | |
| 18 | SECTION("Test system-state") |
| 19 | { |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 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áš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 63 | auto sysrepo = std::make_shared<velia::system::IETFSystem>(srSess, file); |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 64 | REQUIRE(dataFromSysrepo(client, modulePrefix, SR_DS_OPERATIONAL) == expected); |
| 65 | } |
| 66 | |
| 67 | SECTION("Invalid data (missing VERSION and NAME keys)") |
| 68 | { |
Tomáš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 69 | REQUIRE_THROWS_AS(std::make_shared<velia::system::IETFSystem>(srSess, CMAKE_CURRENT_SOURCE_DIR "/tests/system/missing-keys"), std::out_of_range); |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 70 | } |
| 71 | } |
Tomáš Pecka | 879a603 | 2021-02-03 17:21:48 +0100 | [diff] [blame^] | 72 | |
| 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áš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 83 | } |