blob: fc21867103b1f449a4c0498f6a06db43916447e1 [file] [log] [blame]
Tomáš Pecka55f64f82020-12-10 19:03:30 +01001#include "trompeloeil_doctest.h"
2#include "pretty_printers.h"
3#include "test_log_setup.h"
4#include "test_sysrepo_helpers.h"
5
6/* This is a generic test for the following use-case in the ietf-hardware model
7 * - Process #1 starts and uses sr_set_item to set some data in the "/ietf-hardware:hardware/component" subtree
8 * - Process #2 starts and implements sr_oper_get_items_subscribe for the data in the same subtree
9 * - Process #3 should see all of the data.
10 *
11 * Processes #1 and #2 are started (and stopped) by ctest wrapper script (sysrepo_test_merge_fixture.sh) and their code can be found in sysrepo_test_merge_daemon.cpp
12 * The wrapper script ŕeturns *after* both processes report that sysrepo is initialised (ie., callback is added in #2, items are set in #1).
13 * This is implemented simply via some checks whether file exists (see the sh file).
14 */
15
16using namespace std::chrono_literals;
17
18TEST_CASE("HardwareState with two daemons")
19{
20 TEST_SYSREPO_INIT;
21 TEST_SYSREPO_INIT_LOGS;
22
23 SECTION("Test when both processes are running")
24 {
Václav Kubernát7efd6d52021-11-09 01:31:11 +010025 srSess.switchDatastore(sysrepo::Datastore::Operational);
Tomáš Pecka55f64f82020-12-10 19:03:30 +010026 REQUIRE(dataFromSysrepo(srSess, "/ietf-hardware:hardware") == std::map<std::string, std::string> {
27 {"/component[name='ne']", ""},
28 {"/component[name='ne']/name", "ne"},
29 {"/component[name='ne']/class", "iana-hardware:module"},
30 {"/component[name='ne']/description", "This data was brought to you by process 2 (subscr)."},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +020031 {"/component[name='ne']/state", ""},
Tomáš Pecka55f64f82020-12-10 19:03:30 +010032 {"/component[name='ne:edfa']", ""},
33 {"/component[name='ne:edfa']/name", "ne:edfa"},
34 {"/component[name='ne:edfa']/class", "iana-hardware:module"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +020035 {"/component[name='ne:edfa']/state", ""},
Tomáš Pecka55f64f82020-12-10 19:03:30 +010036 {"/component[name='ne:ctrl']", ""},
37 {"/component[name='ne:ctrl']/name", "ne:ctrl"},
38 {"/component[name='ne:ctrl']/class", "iana-hardware:module"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +020039 {"/component[name='ne:ctrl']/state", ""},
Tomáš Pecka55f64f82020-12-10 19:03:30 +010040 });
Václav Kubernát7efd6d52021-11-09 01:31:11 +010041 srSess.switchDatastore(sysrepo::Datastore::Running);
Tomáš Pecka55f64f82020-12-10 19:03:30 +010042 }
43}