Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.hpp" |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 10 | #include <sysrepo-cpp/Session.hpp> |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 11 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 12 | #ifdef sysrepo_BACKEND |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 13 | #include "sysrepo_access.hpp" |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 14 | using OnInvalidSchemaPathCreate = DatastoreException; |
| 15 | using OnInvalidSchemaPathDelete = void; |
| 16 | using OnInvalidSchemaPathMove = sysrepo::sysrepo_exception; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 17 | using OnInvalidRpcPath = sysrepo::sysrepo_exception; |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 18 | using OnKeyNotFound = void; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 19 | using OnRPC = void; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 20 | #elif defined(netconf_BACKEND) |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 21 | using OnInvalidSchemaPathCreate = std::runtime_error; |
| 22 | using OnInvalidSchemaPathDelete = std::runtime_error; |
| 23 | using OnInvalidSchemaPathMove = std::runtime_error; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 24 | using OnInvalidRpcPath = std::runtime_error; |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 25 | using OnKeyNotFound = std::runtime_error; |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 26 | using OnRPC = void; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 27 | #include "netconf_access.hpp" |
| 28 | #include "netopeer_vars.hpp" |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 29 | #elif defined(yang_BACKEND) |
| 30 | #include <fstream> |
| 31 | #include "yang_access.hpp" |
| 32 | #include "yang_access_test_vars.hpp" |
| 33 | using OnInvalidSchemaPathCreate = DatastoreException; |
| 34 | using OnInvalidSchemaPathDelete = DatastoreException; |
| 35 | using OnInvalidSchemaPathMove = DatastoreException; |
| 36 | using OnInvalidRpcPath = DatastoreException; |
| 37 | using OnKeyNotFound = DatastoreException; |
| 38 | using OnRPC = std::logic_error; |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 39 | #else |
| 40 | #error "Unknown backend" |
| 41 | #endif |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 42 | #include "pretty_printers.hpp" |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 43 | #include "sysrepo_subscription.hpp" |
Václav Kubernát | 8e121ff | 2019-10-15 15:47:45 +0200 | [diff] [blame] | 44 | #include "utils.hpp" |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 45 | |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 46 | using namespace std::literals::string_literals; |
| 47 | |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 48 | class MockRecorder : public trompeloeil::mock_interface<Recorder> { |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 49 | public: |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 50 | IMPLEMENT_MOCK3(write); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 53 | class MockDataSupplier : public trompeloeil::mock_interface<DataSupplier> { |
| 54 | public: |
| 55 | IMPLEMENT_CONST_MOCK1(get_data); |
| 56 | }; |
| 57 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 58 | namespace { |
| 59 | template <class ...> constexpr std::false_type always_false [[maybe_unused]] {}; |
| 60 | template <class Exception, typename Callable> void catching(const Callable& what) { |
| 61 | |
| 62 | if constexpr (std::is_same_v<Exception, void>) { |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 63 | what(); |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 64 | } else if constexpr (std::is_same<Exception, std::runtime_error>()) { |
| 65 | // cannot use REQUIRE_THROWS_AS(..., Exception) directly because that one |
| 66 | // needs an extra `typename` deep in the bowels of doctest |
| 67 | REQUIRE_THROWS_AS(what(), std::runtime_error); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 68 | } else if constexpr (std::is_same<Exception, std::logic_error>()) { |
| 69 | REQUIRE_THROWS_AS(what(), std::logic_error); |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 70 | } else if constexpr (std::is_same<Exception, DatastoreException>()) { |
| 71 | REQUIRE_THROWS_AS(what(), DatastoreException); |
| 72 | } else if constexpr (std::is_same<Exception, sysrepo::sysrepo_exception>()) { |
| 73 | REQUIRE_THROWS_AS(what(), sysrepo::sysrepo_exception); |
| 74 | } else { |
| 75 | static_assert(always_false<Exception>); // https://stackoverflow.com/a/53945549/2245623 |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 76 | } |
| 77 | } |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 78 | } |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 79 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 80 | #if defined(yang_BACKEND) |
| 81 | class TestYangAccess : public YangAccess { |
| 82 | public: |
| 83 | void commitChanges() override |
| 84 | { |
| 85 | YangAccess::commitChanges(); |
| 86 | dumpToSysrepo(); |
| 87 | } |
| 88 | |
| 89 | void copyConfig(const Datastore source, const Datastore destination) override |
| 90 | { |
| 91 | YangAccess::copyConfig(source, destination); |
| 92 | dumpToSysrepo(); |
| 93 | } |
| 94 | |
| 95 | private: |
| 96 | void dumpToSysrepo() |
| 97 | { |
| 98 | { |
| 99 | std::ofstream of(testConfigFile); |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 100 | of << dump(DataFormat::Xml); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 101 | } |
| 102 | auto command = std::string(sysrepocfgExecutable) + " --import=" + testConfigFile + " --format=xml --datastore=running example-schema"; |
| 103 | REQUIRE(std::system(command.c_str()) == 0); |
| 104 | } |
| 105 | }; |
| 106 | #endif |
| 107 | |
Václav Kubernát | 8e121ff | 2019-10-15 15:47:45 +0200 | [diff] [blame] | 108 | TEST_CASE("setting/getting values") |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 109 | { |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 110 | trompeloeil::sequence seq1; |
| 111 | MockRecorder mock; |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 112 | SysrepoSubscription subscription("example-schema", &mock); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 113 | |
| 114 | #ifdef sysrepo_BACKEND |
Václav Kubernát | 715c85c | 2020-04-14 01:46:08 +0200 | [diff] [blame] | 115 | SysrepoAccess datastore("netconf-cli-test", Datastore::Running); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 116 | #elif defined(netconf_BACKEND) |
| 117 | NetconfAccess datastore(NETOPEER_SOCKET_PATH); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 118 | #elif defined(yang_BACKEND) |
| 119 | TestYangAccess datastore; |
| 120 | datastore.addSchemaDir(schemaDir); |
| 121 | datastore.addSchemaFile(exampleSchemaFile); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 122 | #else |
| 123 | #error "Unknown backend" |
| 124 | #endif |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 125 | |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 126 | |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 127 | SECTION("set leafInt8 to -128") |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 128 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 129 | REQUIRE_CALL(mock, write("/example-schema:leafInt8", std::nullopt, "-128"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 130 | datastore.setLeaf("/example-schema:leafInt8", int8_t{-128}); |
| 131 | datastore.commitChanges(); |
| 132 | } |
| 133 | |
| 134 | SECTION("set leafInt16 to -32768") |
| 135 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 136 | REQUIRE_CALL(mock, write("/example-schema:leafInt16", std::nullopt, "-32768"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 137 | datastore.setLeaf("/example-schema:leafInt16", int16_t{-32768}); |
| 138 | datastore.commitChanges(); |
| 139 | } |
| 140 | |
| 141 | SECTION("set leafInt32 to -2147483648") |
| 142 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 143 | REQUIRE_CALL(mock, write("/example-schema:leafInt32", std::nullopt, "-2147483648"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 144 | datastore.setLeaf("/example-schema:leafInt32", int32_t{-2147483648}); |
| 145 | datastore.commitChanges(); |
| 146 | } |
| 147 | |
| 148 | SECTION("set leafInt64 to -50000000000") |
| 149 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 150 | REQUIRE_CALL(mock, write("/example-schema:leafInt64", std::nullopt, "-50000000000"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 151 | datastore.setLeaf("/example-schema:leafInt64", int64_t{-50000000000}); |
| 152 | datastore.commitChanges(); |
| 153 | } |
| 154 | |
| 155 | SECTION("set leafUInt8 to 255") |
| 156 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 157 | REQUIRE_CALL(mock, write("/example-schema:leafUInt8", std::nullopt, "255"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 158 | datastore.setLeaf("/example-schema:leafUInt8", uint8_t{255}); |
| 159 | datastore.commitChanges(); |
| 160 | } |
| 161 | |
| 162 | SECTION("set leafUInt16 to 65535") |
| 163 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 164 | REQUIRE_CALL(mock, write("/example-schema:leafUInt16", std::nullopt, "65535"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 165 | datastore.setLeaf("/example-schema:leafUInt16", uint16_t{65535}); |
| 166 | datastore.commitChanges(); |
| 167 | } |
| 168 | |
| 169 | SECTION("set leafUInt32 to 4294967295") |
| 170 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 171 | REQUIRE_CALL(mock, write("/example-schema:leafUInt32", std::nullopt, "4294967295"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 172 | datastore.setLeaf("/example-schema:leafUInt32", uint32_t{4294967295}); |
| 173 | datastore.commitChanges(); |
| 174 | } |
| 175 | |
| 176 | SECTION("set leafUInt64 to 50000000000") |
| 177 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 178 | REQUIRE_CALL(mock, write("/example-schema:leafUInt64", std::nullopt, "50000000000"s)); |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame] | 179 | datastore.setLeaf("/example-schema:leafUInt64", uint64_t{50000000000}); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 180 | datastore.commitChanges(); |
| 181 | } |
| 182 | |
| 183 | SECTION("set leafEnum to coze") |
| 184 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 185 | REQUIRE_CALL(mock, write("/example-schema:leafEnum", std::nullopt, "coze"s)); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 186 | datastore.setLeaf("/example-schema:leafEnum", enum_{"coze"}); |
| 187 | datastore.commitChanges(); |
| 188 | } |
| 189 | |
| 190 | SECTION("set leafDecimal to 123.544") |
| 191 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 192 | REQUIRE_CALL(mock, write("/example-schema:leafDecimal", std::nullopt, "123.544"s)); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 193 | datastore.setLeaf("/example-schema:leafDecimal", 123.544); |
| 194 | datastore.commitChanges(); |
| 195 | } |
| 196 | |
Jan Kundrát | d287286 | 2020-06-18 21:02:00 +0200 | [diff] [blame] | 197 | SECTION("set a string, then delete it") |
| 198 | { |
| 199 | REQUIRE_CALL(mock, write("/example-schema:leafString", std::nullopt, "blah"s)); |
| 200 | datastore.setLeaf("/example-schema:leafString", "blah"s); |
| 201 | datastore.commitChanges(); |
| 202 | DatastoreAccess::Tree expected{{"/example-schema:leafString", "blah"s}}; |
| 203 | REQUIRE(datastore.getItems("/example-schema:leafString") == expected); |
| 204 | |
| 205 | REQUIRE_CALL(mock, write("/example-schema:leafString", "blah"s, std::nullopt)); |
| 206 | datastore.deleteItem("/example-schema:leafString"); |
| 207 | datastore.commitChanges(); |
| 208 | expected.clear(); |
| 209 | REQUIRE(datastore.getItems("/example-schema:leafString") == expected); |
| 210 | } |
| 211 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 212 | SECTION("set a non-existing leaf") |
| 213 | { |
| 214 | catching<OnInvalidSchemaPathCreate>([&]{ |
| 215 | datastore.setLeaf("/example-schema:non-existing", "what"s); |
| 216 | }); |
| 217 | } |
| 218 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 219 | SECTION("create presence container") |
| 220 | { |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 221 | REQUIRE(datastore.dump(DataFormat::Json).find("example-schema:pContainer") == std::string::npos); |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 222 | REQUIRE_CALL(mock, write("/example-schema:pContainer", std::nullopt, ""s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 223 | datastore.createItem("/example-schema:pContainer"); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 224 | datastore.commitChanges(); |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 225 | REQUIRE(datastore.dump(DataFormat::Json).find("example-schema:pContainer") != std::string::npos); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Václav Kubernát | cc7a93f | 2020-02-04 11:48:15 +0100 | [diff] [blame] | 228 | SECTION("create/delete a list instance") |
Václav Kubernát | 45f4a82 | 2019-05-29 21:10:50 +0200 | [diff] [blame] | 229 | { |
Václav Kubernát | cc7a93f | 2020-02-04 11:48:15 +0100 | [diff] [blame] | 230 | { |
| 231 | REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']", std::nullopt, ""s)); |
| 232 | REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']/name", std::nullopt, "Nguyen"s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 233 | datastore.createItem("/example-schema:person[name='Nguyen']"); |
Václav Kubernát | cc7a93f | 2020-02-04 11:48:15 +0100 | [diff] [blame] | 234 | datastore.commitChanges(); |
| 235 | } |
| 236 | { |
| 237 | REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']", ""s, std::nullopt)); |
| 238 | REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']/name", "Nguyen"s, std::nullopt)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 239 | datastore.deleteItem("/example-schema:person[name='Nguyen']"); |
Václav Kubernát | cc7a93f | 2020-02-04 11:48:15 +0100 | [diff] [blame] | 240 | datastore.commitChanges(); |
| 241 | } |
Václav Kubernát | 45f4a82 | 2019-05-29 21:10:50 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 244 | SECTION("deleting non-existing list keys") |
| 245 | { |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 246 | catching<OnKeyNotFound>([&]{ |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 247 | datastore.deleteItem("/example-schema:person[name='non existing']"); |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 248 | datastore.commitChanges(); |
| 249 | }); |
| 250 | } |
| 251 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 252 | SECTION("accessing non-existing schema nodes as a list") |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 253 | { |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 254 | catching<OnInvalidSchemaPathCreate>([&]{ |
| 255 | datastore.createItem("/example-schema:non-existing-list[xxx='blah']"); |
| 256 | datastore.commitChanges(); |
| 257 | }); |
| 258 | catching<OnInvalidSchemaPathDelete>([&]{ |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 259 | datastore.deleteItem("/example-schema:non-existing-list[xxx='non existing']"); |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 260 | datastore.commitChanges(); |
| 261 | }); |
| 262 | } |
| 263 | |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 264 | SECTION("leafref pointing to a key of a list") |
| 265 | { |
| 266 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 267 | REQUIRE_CALL(mock, write("/example-schema:person[name='Dan']", std::nullopt, ""s)); |
| 268 | REQUIRE_CALL(mock, write("/example-schema:person[name='Dan']/name", std::nullopt, "Dan"s)); |
| 269 | REQUIRE_CALL(mock, write("/example-schema:person[name='Elfi']", std::nullopt, ""s)); |
| 270 | REQUIRE_CALL(mock, write("/example-schema:person[name='Elfi']/name", std::nullopt, "Elfi"s)); |
| 271 | REQUIRE_CALL(mock, write("/example-schema:person[name='Kolafa']", std::nullopt, ""s)); |
| 272 | REQUIRE_CALL(mock, write("/example-schema:person[name='Kolafa']/name", std::nullopt, "Kolafa"s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 273 | datastore.createItem("/example-schema:person[name='Dan']"); |
| 274 | datastore.createItem("/example-schema:person[name='Elfi']"); |
| 275 | datastore.createItem("/example-schema:person[name='Kolafa']"); |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 276 | datastore.commitChanges(); |
| 277 | } |
| 278 | |
Václav Kubernát | 7b191ce | 2020-06-30 16:22:53 +0200 | [diff] [blame] | 279 | std::string value; |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 280 | SECTION("Dan") |
| 281 | { |
Václav Kubernát | 7b191ce | 2020-06-30 16:22:53 +0200 | [diff] [blame] | 282 | value = "Dan"; |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | SECTION("Elfi") |
| 286 | { |
Václav Kubernát | 7b191ce | 2020-06-30 16:22:53 +0200 | [diff] [blame] | 287 | value = "Elfi"; |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | SECTION("Kolafa") |
| 291 | { |
Václav Kubernát | 7b191ce | 2020-06-30 16:22:53 +0200 | [diff] [blame] | 292 | value = "Kolafa"; |
| 293 | } |
| 294 | |
| 295 | datastore.setLeaf("/example-schema:bossPerson", value); |
| 296 | { |
| 297 | REQUIRE_CALL(mock, write("/example-schema:bossPerson", std::nullopt, value)); |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 298 | datastore.commitChanges(); |
| 299 | } |
Václav Kubernát | 7b191ce | 2020-06-30 16:22:53 +0200 | [diff] [blame] | 300 | REQUIRE(datastore.getItems("/example-schema:bossPerson") == DatastoreAccess::Tree{{"/example-schema:bossPerson", value}}); |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 301 | } |
Václav Kubernát | 8e121ff | 2019-10-15 15:47:45 +0200 | [diff] [blame] | 302 | SECTION("bool values get correctly represented as bools") |
| 303 | { |
| 304 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 305 | REQUIRE_CALL(mock, write("/example-schema:down", std::nullopt, "true"s)); |
Václav Kubernát | 8e121ff | 2019-10-15 15:47:45 +0200 | [diff] [blame] | 306 | datastore.setLeaf("/example-schema:down", bool{true}); |
| 307 | datastore.commitChanges(); |
| 308 | } |
| 309 | |
Jan Kundrát | b331b55 | 2020-01-23 15:25:29 +0100 | [diff] [blame] | 310 | DatastoreAccess::Tree expected{{"/example-schema:down", bool{true}}}; |
Václav Kubernát | 8e121ff | 2019-10-15 15:47:45 +0200 | [diff] [blame] | 311 | REQUIRE(datastore.getItems("/example-schema:down") == expected); |
| 312 | } |
Václav Kubernát | 3efb5ca | 2019-10-09 20:07:40 +0200 | [diff] [blame] | 313 | |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 314 | SECTION("getting items from the whole module") |
| 315 | { |
| 316 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 317 | REQUIRE_CALL(mock, write("/example-schema:up", std::nullopt, "true"s)); |
| 318 | REQUIRE_CALL(mock, write("/example-schema:down", std::nullopt, "false"s)); |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 319 | datastore.setLeaf("/example-schema:up", bool{true}); |
| 320 | datastore.setLeaf("/example-schema:down", bool{false}); |
| 321 | datastore.commitChanges(); |
| 322 | } |
| 323 | |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 324 | DatastoreAccess::Tree expected{ |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 325 | // Sysrepo always returns containers when getting values, but |
| 326 | // libnetconf does not. This is fine by the YANG standard: |
| 327 | // https://tools.ietf.org/html/rfc7950#section-7.5.7 Furthermore, |
| 328 | // NetconfAccess implementation actually only iterates over leafs, |
| 329 | // so even if libnetconf did include containers, they wouldn't get |
| 330 | // shown here anyway. With sysrepo2, this won't be necessary, |
| 331 | // because it'll use the same data structure as libnetconf, so the |
| 332 | // results will be consistent. |
| 333 | #ifdef sysrepo_BACKEND |
Václav Kubernát | da8e4b9 | 2020-02-04 11:56:30 +0100 | [diff] [blame] | 334 | {"/example-schema:inventory", special_{SpecialValue::Container}}, |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 335 | {"/example-schema:lol", special_{SpecialValue::Container}}, |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 336 | #endif |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 337 | {"/example-schema:up", bool{true}}, |
| 338 | {"/example-schema:down", bool{false}}}; |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 339 | REQUIRE(datastore.getItems("/example-schema:*") == expected); |
| 340 | } |
| 341 | |
Václav Kubernát | 152ce22 | 2019-12-19 12:23:32 +0100 | [diff] [blame] | 342 | SECTION("getItems returns correct datatypes") |
| 343 | { |
| 344 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 345 | REQUIRE_CALL(mock, write("/example-schema:leafEnum", std::nullopt, "lol"s)); |
Václav Kubernát | 152ce22 | 2019-12-19 12:23:32 +0100 | [diff] [blame] | 346 | datastore.setLeaf("/example-schema:leafEnum", enum_{"lol"}); |
| 347 | datastore.commitChanges(); |
| 348 | } |
Jan Kundrát | b331b55 | 2020-01-23 15:25:29 +0100 | [diff] [blame] | 349 | DatastoreAccess::Tree expected{{"/example-schema:leafEnum", enum_{"lol"}}}; |
Václav Kubernát | 152ce22 | 2019-12-19 12:23:32 +0100 | [diff] [blame] | 350 | |
| 351 | REQUIRE(datastore.getItems("/example-schema:leafEnum") == expected); |
| 352 | } |
| 353 | |
Václav Kubernát | d812cfb | 2020-01-07 17:30:20 +0100 | [diff] [blame] | 354 | SECTION("getItems on a list") |
| 355 | { |
| 356 | { |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 357 | REQUIRE_CALL(mock, write("/example-schema:person[name='Jan']", std::nullopt, ""s)); |
| 358 | REQUIRE_CALL(mock, write("/example-schema:person[name='Jan']/name", std::nullopt, "Jan"s)); |
| 359 | REQUIRE_CALL(mock, write("/example-schema:person[name='Michal']", std::nullopt, ""s)); |
| 360 | REQUIRE_CALL(mock, write("/example-schema:person[name='Michal']/name", std::nullopt, "Michal"s)); |
| 361 | REQUIRE_CALL(mock, write("/example-schema:person[name='Petr']", std::nullopt, ""s)); |
| 362 | REQUIRE_CALL(mock, write("/example-schema:person[name='Petr']/name", std::nullopt, "Petr"s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 363 | datastore.createItem("/example-schema:person[name='Jan']"); |
| 364 | datastore.createItem("/example-schema:person[name='Michal']"); |
| 365 | datastore.createItem("/example-schema:person[name='Petr']"); |
Václav Kubernát | d812cfb | 2020-01-07 17:30:20 +0100 | [diff] [blame] | 366 | datastore.commitChanges(); |
| 367 | } |
Jan Kundrát | b331b55 | 2020-01-23 15:25:29 +0100 | [diff] [blame] | 368 | DatastoreAccess::Tree expected{ |
Václav Kubernát | 144729d | 2020-01-08 15:20:35 +0100 | [diff] [blame] | 369 | {"/example-schema:person[name='Jan']", special_{SpecialValue::List}}, |
Václav Kubernát | d812cfb | 2020-01-07 17:30:20 +0100 | [diff] [blame] | 370 | {"/example-schema:person[name='Jan']/name", std::string{"Jan"}}, |
Václav Kubernát | 144729d | 2020-01-08 15:20:35 +0100 | [diff] [blame] | 371 | {"/example-schema:person[name='Michal']", special_{SpecialValue::List}}, |
Václav Kubernát | d812cfb | 2020-01-07 17:30:20 +0100 | [diff] [blame] | 372 | {"/example-schema:person[name='Michal']/name", std::string{"Michal"}}, |
Václav Kubernát | 144729d | 2020-01-08 15:20:35 +0100 | [diff] [blame] | 373 | {"/example-schema:person[name='Petr']", special_{SpecialValue::List}}, |
Václav Kubernát | d812cfb | 2020-01-07 17:30:20 +0100 | [diff] [blame] | 374 | {"/example-schema:person[name='Petr']/name", std::string{"Petr"}} |
| 375 | }; |
| 376 | |
| 377 | REQUIRE(datastore.getItems("/example-schema:person") == expected); |
| 378 | } |
| 379 | |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 380 | SECTION("presence containers") |
| 381 | { |
| 382 | DatastoreAccess::Tree expected; |
| 383 | // Make sure it's not there before we create it |
| 384 | REQUIRE(datastore.getItems("/example-schema:pContainer") == expected); |
| 385 | |
| 386 | { |
| 387 | REQUIRE_CALL(mock, write("/example-schema:pContainer", std::nullopt, ""s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 388 | datastore.createItem("/example-schema:pContainer"); |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 389 | datastore.commitChanges(); |
| 390 | } |
| 391 | expected = { |
| 392 | {"/example-schema:pContainer", special_{SpecialValue::PresenceContainer}} |
| 393 | }; |
| 394 | REQUIRE(datastore.getItems("/example-schema:pContainer") == expected); |
| 395 | |
| 396 | // Make sure it's not there after we delete it |
| 397 | { |
| 398 | REQUIRE_CALL(mock, write("/example-schema:pContainer", ""s, std::nullopt)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 399 | datastore.deleteItem("/example-schema:pContainer"); |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 400 | datastore.commitChanges(); |
| 401 | } |
| 402 | expected = {}; |
| 403 | REQUIRE(datastore.getItems("/example-schema:pContainer") == expected); |
Václav Kubernát | da8e4b9 | 2020-02-04 11:56:30 +0100 | [diff] [blame] | 404 | } |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 405 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 406 | SECTION("creating a non-existing schema node as a container") |
| 407 | { |
| 408 | catching<OnInvalidSchemaPathCreate>([&]{ |
| 409 | datastore.createItem("/example-schema:non-existing-presence-container"); |
| 410 | datastore.commitChanges(); |
| 411 | }); |
| 412 | } |
| 413 | |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 414 | SECTION("deleting a non-existing schema node as a container or leaf") |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 415 | { |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 416 | catching<OnInvalidSchemaPathDelete>([&]{ |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 417 | datastore.deleteItem("/example-schema:non-existing-presence-container"); |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 418 | datastore.commitChanges(); |
| 419 | }); |
| 420 | } |
| 421 | |
Václav Kubernát | da8e4b9 | 2020-02-04 11:56:30 +0100 | [diff] [blame] | 422 | SECTION("nested presence container") |
| 423 | { |
| 424 | DatastoreAccess::Tree expected; |
| 425 | // Make sure it's not there before we create it |
| 426 | REQUIRE(datastore.getItems("/example-schema:inventory/stuff") == expected); |
| 427 | { |
| 428 | REQUIRE_CALL(mock, write("/example-schema:inventory", std::nullopt, ""s)); |
| 429 | REQUIRE_CALL(mock, write("/example-schema:inventory/stuff", std::nullopt, ""s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 430 | datastore.createItem("/example-schema:inventory/stuff"); |
Václav Kubernát | da8e4b9 | 2020-02-04 11:56:30 +0100 | [diff] [blame] | 431 | datastore.commitChanges(); |
| 432 | } |
| 433 | expected = { |
| 434 | {"/example-schema:inventory/stuff", special_{SpecialValue::PresenceContainer}} |
| 435 | }; |
| 436 | REQUIRE(datastore.getItems("/example-schema:inventory/stuff") == expected); |
| 437 | { |
| 438 | REQUIRE_CALL(mock, write("/example-schema:inventory", ""s, std::nullopt)); |
| 439 | REQUIRE_CALL(mock, write("/example-schema:inventory/stuff", ""s, std::nullopt)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 440 | datastore.deleteItem("/example-schema:inventory/stuff"); |
Václav Kubernát | da8e4b9 | 2020-02-04 11:56:30 +0100 | [diff] [blame] | 441 | datastore.commitChanges(); |
| 442 | } |
| 443 | expected = {}; |
| 444 | REQUIRE(datastore.getItems("/example-schema:inventory/stuff") == expected); |
Václav Kubernát | 69aabe9 | 2020-01-24 16:53:12 +0100 | [diff] [blame] | 445 | } |
| 446 | |
Jan Kundrát | bd3169c | 2020-02-03 19:31:34 +0100 | [diff] [blame] | 447 | SECTION("floats") |
| 448 | { |
| 449 | datastore.setLeaf("/example-schema:leafDecimal", 123.4); |
| 450 | REQUIRE_CALL(mock, write("/example-schema:leafDecimal", std::nullopt, "123.4"s)); |
| 451 | datastore.commitChanges(); |
| 452 | DatastoreAccess::Tree expected { |
| 453 | {"/example-schema:leafDecimal", 123.4}, |
| 454 | }; |
| 455 | REQUIRE(datastore.getItems("/example-schema:leafDecimal") == expected); |
| 456 | } |
| 457 | |
Jan Kundrát | 3ff5012 | 2020-05-07 00:37:50 +0200 | [diff] [blame] | 458 | SECTION("unions") |
| 459 | { |
| 460 | datastore.setLeaf("/example-schema:unionIntString", int32_t{10}); |
| 461 | REQUIRE_CALL(mock, write("/example-schema:unionIntString", std::nullopt, "10"s)); |
| 462 | datastore.commitChanges(); |
| 463 | DatastoreAccess::Tree expected { |
| 464 | {"/example-schema:unionIntString", int32_t{10}}, |
| 465 | }; |
| 466 | REQUIRE(datastore.getItems("/example-schema:unionIntString") == expected); |
| 467 | } |
| 468 | |
Jan Kundrát | 0d8abd1 | 2020-05-07 02:00:14 +0200 | [diff] [blame] | 469 | SECTION("identityref") { |
| 470 | datastore.setLeaf("/example-schema:beast", identityRef_{"example-schema", "Mammal"}); |
| 471 | REQUIRE_CALL(mock, write("/example-schema:beast", std::nullopt, "example-schema:Mammal"s)); |
| 472 | datastore.commitChanges(); |
| 473 | DatastoreAccess::Tree expected { |
| 474 | {"/example-schema:beast", identityRef_{"example-schema", "Mammal"}}, |
| 475 | }; |
| 476 | REQUIRE(datastore.getItems("/example-schema:beast") == expected); |
| 477 | |
| 478 | datastore.setLeaf("/example-schema:beast", identityRef_{"Whale"}); |
| 479 | REQUIRE_CALL(mock, write("/example-schema:beast", "example-schema:Mammal", "example-schema:Whale"s)); |
| 480 | datastore.commitChanges(); |
| 481 | expected = { |
| 482 | {"/example-schema:beast", identityRef_{"example-schema", "Whale"}}, |
| 483 | }; |
| 484 | REQUIRE(datastore.getItems("/example-schema:beast") == expected); |
| 485 | } |
| 486 | |
Jan Kundrát | 6898544 | 2020-05-07 02:15:34 +0200 | [diff] [blame] | 487 | SECTION("binary") |
| 488 | { |
| 489 | datastore.setLeaf("/example-schema:blob", binary_{"cHduegByIQ=="s}); |
| 490 | REQUIRE_CALL(mock, write("/example-schema:blob", std::nullopt, "cHduegByIQ=="s)); |
| 491 | datastore.commitChanges(); |
| 492 | DatastoreAccess::Tree expected { |
| 493 | {"/example-schema:blob", binary_{"cHduegByIQ=="s}}, |
| 494 | }; |
| 495 | REQUIRE(datastore.getItems("/example-schema:blob") == expected); |
| 496 | } |
| 497 | |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 498 | SECTION("empty") |
| 499 | { |
| 500 | datastore.setLeaf("/example-schema:dummy", empty_{}); |
| 501 | REQUIRE_CALL(mock, write("/example-schema:dummy", std::nullopt, ""s)); |
| 502 | datastore.commitChanges(); |
| 503 | DatastoreAccess::Tree expected { |
| 504 | {"/example-schema:dummy", empty_{}}, |
| 505 | }; |
| 506 | REQUIRE(datastore.getItems("/example-schema:dummy") == expected); |
| 507 | } |
| 508 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 509 | #if not defined(yang_BACKEND) |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 510 | SECTION("operational data") |
| 511 | { |
| 512 | MockDataSupplier mockOpsData; |
| 513 | OperationalDataSubscription opsDataSub("/example-schema:temperature", mockOpsData); |
| 514 | DatastoreAccess::Tree expected; |
| 515 | std::string xpath; |
| 516 | SECTION("temperature") |
| 517 | { |
| 518 | expected = {{"/example-schema:temperature", int32_t{22}}}; |
| 519 | xpath = "/example-schema:temperature"; |
| 520 | } |
| 521 | |
| 522 | REQUIRE_CALL(mockOpsData, get_data(xpath)).RETURN(expected); |
| 523 | REQUIRE(datastore.getItems(xpath) == expected); |
| 524 | } |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 525 | #endif |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 526 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 527 | SECTION("leaf list") |
| 528 | { |
| 529 | DatastoreAccess::Tree expected; |
| 530 | REQUIRE_CALL(mock, write("/example-schema:addresses", std::nullopt, "0.0.0.0"s)); |
| 531 | REQUIRE_CALL(mock, write("/example-schema:addresses", std::nullopt, "127.0.0.1"s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 532 | datastore.createItem("/example-schema:addresses[.='0.0.0.0']"); |
| 533 | datastore.createItem("/example-schema:addresses[.='127.0.0.1']"); |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 534 | datastore.commitChanges(); |
| 535 | expected = { |
| 536 | {"/example-schema:addresses", special_{SpecialValue::LeafList}}, |
| 537 | {"/example-schema:addresses[.='0.0.0.0']", "0.0.0.0"s}, |
| 538 | {"/example-schema:addresses[.='127.0.0.1']", "127.0.0.1"s}, |
| 539 | }; |
| 540 | REQUIRE(datastore.getItems("/example-schema:addresses") == expected); |
| 541 | |
| 542 | REQUIRE_CALL(mock, write("/example-schema:addresses", "0.0.0.0"s, std::nullopt)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 543 | datastore.deleteItem("/example-schema:addresses[.='0.0.0.0']"); |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 544 | datastore.commitChanges(); |
| 545 | expected = { |
| 546 | {"/example-schema:addresses", special_{SpecialValue::LeafList}}, |
| 547 | {"/example-schema:addresses[.='127.0.0.1']", "127.0.0.1"s}, |
| 548 | }; |
| 549 | REQUIRE(datastore.getItems("/example-schema:addresses") == expected); |
| 550 | |
| 551 | REQUIRE_CALL(mock, write("/example-schema:addresses", "127.0.0.1"s, std::nullopt)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 552 | datastore.deleteItem("/example-schema:addresses[.='127.0.0.1']"); |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 553 | datastore.commitChanges(); |
| 554 | expected = {}; |
| 555 | REQUIRE(datastore.getItems("/example-schema:addresses") == expected); |
| 556 | } |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 557 | |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 558 | SECTION("deleting a non-existing leaf-list") |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 559 | { |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 560 | catching<OnKeyNotFound>([&]{ |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 561 | datastore.deleteItem("/example-schema:addresses[.='non-existing']"); |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 562 | datastore.commitChanges(); |
| 563 | }); |
| 564 | } |
| 565 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 566 | SECTION("accessing a non-existing schema node as a leaf-list") |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 567 | { |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 568 | catching<OnInvalidSchemaPathCreate>([&]{ |
| 569 | datastore.createItem("/example-schema:non-existing[.='non-existing']"); |
| 570 | datastore.commitChanges(); |
| 571 | }); |
| 572 | |
| 573 | catching<OnInvalidSchemaPathDelete>([&]{ |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 574 | datastore.deleteItem("/example-schema:non-existing[.='non-existing']"); |
Jan Kundrát | 3867c9e | 2020-06-18 20:26:45 +0200 | [diff] [blame] | 575 | datastore.commitChanges(); |
| 576 | }); |
| 577 | } |
| 578 | |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 579 | SECTION("copying data from startup refreshes the data") |
| 580 | { |
| 581 | { |
| 582 | REQUIRE(datastore.getItems("/example-schema:leafInt16") == DatastoreAccess::Tree{}); |
| 583 | REQUIRE_CALL(mock, write("/example-schema:leafInt16", std::nullopt, "123"s)); |
| 584 | datastore.setLeaf("/example-schema:leafInt16", int16_t{123}); |
| 585 | datastore.commitChanges(); |
| 586 | } |
| 587 | REQUIRE(datastore.getItems("/example-schema:leafInt16") == DatastoreAccess::Tree{{"/example-schema:leafInt16", int16_t{123}}}); |
| 588 | REQUIRE_CALL(mock, write("/example-schema:leafInt16", "123"s, std::nullopt)); |
| 589 | datastore.copyConfig(Datastore::Startup, Datastore::Running); |
| 590 | REQUIRE(datastore.getItems("/example-schema:leafInt16") == DatastoreAccess::Tree{}); |
| 591 | } |
| 592 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 593 | SECTION("moving leaflist instances") |
| 594 | { |
| 595 | DatastoreAccess::Tree expected; |
| 596 | { |
| 597 | // sysrepo does this twice for some reason, it's possibly a bug |
| 598 | REQUIRE_CALL(mock, write("/example-schema:protocols", std::nullopt, "http"s)).TIMES(2); |
| 599 | REQUIRE_CALL(mock, write("/example-schema:protocols", std::nullopt, "ftp"s)); |
| 600 | REQUIRE_CALL(mock, write("/example-schema:protocols", std::nullopt, "pop3"s)); |
| 601 | REQUIRE_CALL(mock, write("/example-schema:protocols", "http"s, "ftp"s)); |
| 602 | REQUIRE_CALL(mock, write("/example-schema:protocols", "ftp"s, "pop3"s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 603 | datastore.createItem("/example-schema:protocols[.='http']"); |
| 604 | datastore.createItem("/example-schema:protocols[.='ftp']"); |
| 605 | datastore.createItem("/example-schema:protocols[.='pop3']"); |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 606 | datastore.commitChanges(); |
| 607 | expected = { |
| 608 | {"/example-schema:protocols", special_{SpecialValue::LeafList}}, |
| 609 | {"/example-schema:protocols[.='http']", "http"s}, |
| 610 | {"/example-schema:protocols[.='ftp']", "ftp"s}, |
| 611 | {"/example-schema:protocols[.='pop3']", "pop3"s}, |
| 612 | }; |
| 613 | REQUIRE(datastore.getItems("/example-schema:protocols") == expected); |
| 614 | } |
| 615 | |
| 616 | std::string sourcePath; |
| 617 | SECTION("begin") |
| 618 | { |
| 619 | REQUIRE_CALL(mock, write("/example-schema:protocols", std::nullopt, "pop3"s)); |
| 620 | sourcePath = "/example-schema:protocols[.='pop3']"; |
| 621 | datastore.moveItem(sourcePath, yang::move::Absolute::Begin); |
| 622 | datastore.commitChanges(); |
| 623 | expected = { |
| 624 | {"/example-schema:protocols", special_{SpecialValue::LeafList}}, |
| 625 | {"/example-schema:protocols[.='pop3']", "pop3"s}, |
| 626 | {"/example-schema:protocols[.='http']", "http"s}, |
| 627 | {"/example-schema:protocols[.='ftp']", "ftp"s}, |
| 628 | }; |
| 629 | REQUIRE(datastore.getItems("/example-schema:protocols") == expected); |
| 630 | } |
| 631 | |
| 632 | SECTION("end") |
| 633 | { |
| 634 | sourcePath = "/example-schema:protocols[.='http']"; |
| 635 | REQUIRE_CALL(mock, write("/example-schema:protocols", "pop3"s, "http"s)); |
| 636 | datastore.moveItem(sourcePath, yang::move::Absolute::End); |
| 637 | datastore.commitChanges(); |
| 638 | expected = { |
| 639 | {"/example-schema:protocols", special_{SpecialValue::LeafList}}, |
| 640 | {"/example-schema:protocols[.='ftp']", "ftp"s}, |
| 641 | {"/example-schema:protocols[.='pop3']", "pop3"s}, |
| 642 | {"/example-schema:protocols[.='http']", "http"s}, |
| 643 | }; |
| 644 | REQUIRE(datastore.getItems("/example-schema:protocols") == expected); |
| 645 | } |
| 646 | |
| 647 | SECTION("after") |
| 648 | { |
| 649 | sourcePath = "/example-schema:protocols[.='http']"; |
| 650 | REQUIRE_CALL(mock, write("/example-schema:protocols", "ftp"s, "http"s)); |
| 651 | datastore.moveItem(sourcePath, yang::move::Relative{yang::move::Relative::Position::After, {{".", "ftp"s}}}); |
| 652 | datastore.commitChanges(); |
| 653 | expected = { |
| 654 | {"/example-schema:protocols", special_{SpecialValue::LeafList}}, |
| 655 | {"/example-schema:protocols[.='ftp']", "ftp"s}, |
| 656 | {"/example-schema:protocols[.='http']", "http"s}, |
| 657 | {"/example-schema:protocols[.='pop3']", "pop3"s}, |
| 658 | }; |
| 659 | REQUIRE(datastore.getItems("/example-schema:protocols") == expected); |
| 660 | } |
| 661 | |
| 662 | SECTION("before") |
| 663 | { |
| 664 | sourcePath = "/example-schema:protocols[.='http']"; |
| 665 | REQUIRE_CALL(mock, write("/example-schema:protocols", "ftp"s, "http"s)); |
| 666 | datastore.moveItem(sourcePath, yang::move::Relative{yang::move::Relative::Position::Before, {{".", "pop3"s}}}); |
| 667 | datastore.commitChanges(); |
| 668 | expected = { |
| 669 | {"/example-schema:protocols", special_{SpecialValue::LeafList}}, |
| 670 | {"/example-schema:protocols[.='ftp']", "ftp"s}, |
| 671 | {"/example-schema:protocols[.='http']", "http"s}, |
| 672 | {"/example-schema:protocols[.='pop3']", "pop3"s}, |
| 673 | }; |
| 674 | REQUIRE(datastore.getItems("/example-schema:protocols") == expected); |
| 675 | } |
| 676 | } |
| 677 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 678 | SECTION("moving non-existing schema nodes") |
| 679 | { |
| 680 | catching<OnInvalidSchemaPathMove>([&]{ |
| 681 | datastore.moveItem("/example-schema:non-existing", yang::move::Absolute::Begin); |
| 682 | datastore.commitChanges(); |
| 683 | }); |
| 684 | } |
| 685 | |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 686 | SECTION("moving list instances") |
| 687 | { |
| 688 | DatastoreAccess::Tree expected; |
| 689 | { |
| 690 | // sysrepo does this twice for some reason, it's possibly a bug |
| 691 | REQUIRE_CALL(mock, write("/example-schema:players[name='John']", std::nullopt, ""s)).TIMES(2); |
| 692 | REQUIRE_CALL(mock, write("/example-schema:players[name='John']/name", std::nullopt, "John"s)); |
| 693 | REQUIRE_CALL(mock, write("/example-schema:players[name='Eve']", std::nullopt, ""s)); |
| 694 | REQUIRE_CALL(mock, write("/example-schema:players[name='Eve']", ""s, ""s)); |
| 695 | REQUIRE_CALL(mock, write("/example-schema:players[name='Eve']/name", std::nullopt, "Eve"s)); |
| 696 | REQUIRE_CALL(mock, write("/example-schema:players[name='Adam']", std::nullopt, ""s)); |
| 697 | REQUIRE_CALL(mock, write("/example-schema:players[name='Adam']/name", std::nullopt, "Adam"s)); |
| 698 | REQUIRE_CALL(mock, write("/example-schema:players[name='Adam']", ""s, ""s)); |
Jan Kundrát | cbf288b | 2020-06-18 20:44:39 +0200 | [diff] [blame] | 699 | datastore.createItem("/example-schema:players[name='John']"); |
| 700 | datastore.createItem("/example-schema:players[name='Eve']"); |
| 701 | datastore.createItem("/example-schema:players[name='Adam']"); |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 702 | datastore.commitChanges(); |
| 703 | expected = { |
| 704 | {"/example-schema:players[name='John']", special_{SpecialValue::List}}, |
| 705 | {"/example-schema:players[name='John']/name", "John"s}, |
| 706 | {"/example-schema:players[name='Eve']", special_{SpecialValue::List}}, |
| 707 | {"/example-schema:players[name='Eve']/name", "Eve"s}, |
| 708 | {"/example-schema:players[name='Adam']", special_{SpecialValue::List}}, |
| 709 | {"/example-schema:players[name='Adam']/name", "Adam"s}, |
| 710 | }; |
| 711 | REQUIRE(datastore.getItems("/example-schema:players") == expected); |
| 712 | } |
| 713 | |
| 714 | std::string sourcePath; |
| 715 | SECTION("begin") |
| 716 | { |
| 717 | sourcePath = "/example-schema:players[name='Adam']"; |
| 718 | REQUIRE_CALL(mock, write("/example-schema:players[name='Adam']", std::nullopt, ""s)); |
| 719 | datastore.moveItem(sourcePath, yang::move::Absolute::Begin); |
| 720 | datastore.commitChanges(); |
| 721 | expected = { |
| 722 | {"/example-schema:players[name='Adam']", special_{SpecialValue::List}}, |
| 723 | {"/example-schema:players[name='Adam']/name", "Adam"s}, |
| 724 | {"/example-schema:players[name='John']", special_{SpecialValue::List}}, |
| 725 | {"/example-schema:players[name='John']/name", "John"s}, |
| 726 | {"/example-schema:players[name='Eve']", special_{SpecialValue::List}}, |
| 727 | {"/example-schema:players[name='Eve']/name", "Eve"s}, |
| 728 | }; |
| 729 | REQUIRE(datastore.getItems("/example-schema:players") == expected); |
| 730 | } |
| 731 | |
| 732 | SECTION("end") |
| 733 | { |
| 734 | sourcePath = "/example-schema:players[name='John']"; |
| 735 | REQUIRE_CALL(mock, write("/example-schema:players[name='John']", ""s, ""s)); |
| 736 | datastore.moveItem(sourcePath, yang::move::Absolute::End); |
| 737 | datastore.commitChanges(); |
| 738 | expected = { |
| 739 | {"/example-schema:players[name='Eve']", special_{SpecialValue::List}}, |
| 740 | {"/example-schema:players[name='Eve']/name", "Eve"s}, |
| 741 | {"/example-schema:players[name='Adam']", special_{SpecialValue::List}}, |
| 742 | {"/example-schema:players[name='Adam']/name", "Adam"s}, |
| 743 | {"/example-schema:players[name='John']", special_{SpecialValue::List}}, |
| 744 | {"/example-schema:players[name='John']/name", "John"s}, |
| 745 | }; |
| 746 | REQUIRE(datastore.getItems("/example-schema:players") == expected); |
| 747 | } |
| 748 | |
| 749 | SECTION("after") |
| 750 | { |
| 751 | sourcePath = "/example-schema:players[name='John']"; |
| 752 | REQUIRE_CALL(mock, write("/example-schema:players[name='John']", ""s, ""s)); |
| 753 | datastore.moveItem(sourcePath, yang::move::Relative{yang::move::Relative::Position::After, {{"name", "Eve"s}}}); |
| 754 | datastore.commitChanges(); |
| 755 | expected = { |
| 756 | {"/example-schema:players[name='Eve']", special_{SpecialValue::List}}, |
| 757 | {"/example-schema:players[name='Eve']/name", "Eve"s}, |
| 758 | {"/example-schema:players[name='John']", special_{SpecialValue::List}}, |
| 759 | {"/example-schema:players[name='John']/name", "John"s}, |
| 760 | {"/example-schema:players[name='Adam']", special_{SpecialValue::List}}, |
| 761 | {"/example-schema:players[name='Adam']/name", "Adam"s}, |
| 762 | }; |
| 763 | REQUIRE(datastore.getItems("/example-schema:players") == expected); |
| 764 | } |
| 765 | |
| 766 | SECTION("before") |
| 767 | { |
| 768 | sourcePath = "/example-schema:players[name='John']"; |
| 769 | REQUIRE_CALL(mock, write("/example-schema:players[name='John']", ""s, ""s)); |
| 770 | datastore.moveItem(sourcePath, yang::move::Relative{yang::move::Relative::Position::Before, {{"name", "Adam"s}}}); |
| 771 | datastore.commitChanges(); |
| 772 | expected = { |
| 773 | {"/example-schema:players[name='Eve']", special_{SpecialValue::List}}, |
| 774 | {"/example-schema:players[name='Eve']/name", "Eve"s}, |
| 775 | {"/example-schema:players[name='John']", special_{SpecialValue::List}}, |
| 776 | {"/example-schema:players[name='John']/name", "John"s}, |
| 777 | {"/example-schema:players[name='Adam']", special_{SpecialValue::List}}, |
| 778 | {"/example-schema:players[name='Adam']/name", "Adam"s}, |
| 779 | }; |
| 780 | REQUIRE(datastore.getItems("/example-schema:players") == expected); |
| 781 | } |
| 782 | } |
| 783 | |
Václav Kubernát | fa96ac2 | 2020-06-18 17:03:52 +0200 | [diff] [blame] | 784 | SECTION("getting /") |
| 785 | { |
| 786 | { |
| 787 | REQUIRE_CALL(mock, write("/example-schema:leafInt32", std::nullopt, "64"s)); |
| 788 | datastore.setLeaf("/example-schema:leafInt32", 64); |
| 789 | datastore.commitChanges(); |
| 790 | } |
| 791 | |
| 792 | DatastoreAccess::Tree expected{ |
| 793 | // Sysrepo always returns containers when getting values, but |
| 794 | // libnetconf does not. This is fine by the YANG standard: |
| 795 | // https://tools.ietf.org/html/rfc7950#section-7.5.7 Furthermore, |
| 796 | // NetconfAccess implementation actually only iterates over leafs, |
| 797 | // so even if libnetconf did include containers, they wouldn't get |
| 798 | // shown here anyway. With sysrepo2, this won't be necessary, |
| 799 | // because it'll use the same data structure as libnetconf, so the |
| 800 | // results will be consistent. |
| 801 | #ifdef sysrepo_BACKEND |
| 802 | {"/example-schema:inventory", special_{SpecialValue::Container}}, |
| 803 | {"/example-schema:lol", special_{SpecialValue::Container}}, |
| 804 | #endif |
| 805 | {"/example-schema:leafInt32", 64}}; |
| 806 | auto items = datastore.getItems("/"); |
| 807 | // This tests if we at least get the data WE added. |
| 808 | REQUIRE(std::all_of(expected.begin(), expected.end(), [items] (const auto& item) { return std::find(items.begin(), items.end(), item) != items.end(); })); |
| 809 | } |
| 810 | |
Václav Kubernát | 36986c5 | 2020-06-25 10:30:05 +0200 | [diff] [blame] | 811 | SECTION("setting and removing without commit") |
| 812 | { |
| 813 | datastore.setLeaf("/example-schema:leafInt32", 64); |
| 814 | datastore.deleteItem("/example-schema:leafInt32"); |
| 815 | } |
| 816 | |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 817 | SECTION("two key lists") |
| 818 | { |
| 819 | REQUIRE_CALL(mock, write("/example-schema:point[x='12'][y='10']", std::nullopt, ""s)); |
| 820 | REQUIRE_CALL(mock, write("/example-schema:point[x='12'][y='10']/x", std::nullopt, "12"s)); |
| 821 | REQUIRE_CALL(mock, write("/example-schema:point[x='12'][y='10']/y", std::nullopt, "10"s)); |
| 822 | datastore.createItem("/example-schema:point[x='12'][y='10']"); |
| 823 | datastore.commitChanges(); |
| 824 | REQUIRE(datastore.dump(DataFormat::Json).find("example-schema:point") != std::string::npos); |
| 825 | } |
| 826 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 827 | waitForCompletionAndBitMore(seq1); |
| 828 | } |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 829 | |
| 830 | class RpcCb: public sysrepo::Callback { |
| 831 | int rpc(const char *xpath, const ::sysrepo::S_Vals input, ::sysrepo::S_Vals_Holder output, void *) override |
| 832 | { |
| 833 | const auto nukes = "/example-schema:launch-nukes"s; |
| 834 | if (xpath == "/example-schema:noop"s) { |
| 835 | return SR_ERR_OK; |
| 836 | } else if (xpath == nukes) { |
| 837 | uint64_t kilotons = 0; |
| 838 | bool hasCities = false; |
| 839 | for (size_t i = 0; i < input->val_cnt(); ++i) { |
| 840 | const auto& val = input->val(i); |
| 841 | if (val->xpath() == nukes + "/payload/kilotons") { |
| 842 | kilotons = val->data()->get_uint64(); |
| 843 | } else if (val->xpath() == nukes + "/payload") { |
| 844 | // ignore, container |
| 845 | } else if (val->xpath() == nukes + "/description") { |
| 846 | // unused |
| 847 | } else if (std::string_view{val->xpath()}.find(nukes + "/cities") == 0) { |
| 848 | hasCities = true; |
| 849 | } else { |
| 850 | throw std::runtime_error("RPC launch-nukes: unexpected input "s + val->xpath()); |
| 851 | } |
| 852 | } |
| 853 | if (kilotons == 333'666) { |
| 854 | // magic, just do not generate any output. This is important because the NETCONF RPC returns just <ok/>. |
| 855 | return SR_ERR_OK; |
| 856 | } |
| 857 | auto buf = output->allocate(2); |
| 858 | size_t i = 0; |
| 859 | buf->val(i++)->set((nukes + "/blast-radius").c_str(), uint32_t{33'666}); |
| 860 | buf->val(i++)->set((nukes + "/actual-yield").c_str(), static_cast<uint64_t>(1.33 * kilotons)); |
| 861 | if (hasCities) { |
| 862 | buf = output->reallocate(output->val_cnt() + 2); |
| 863 | buf->val(i++)->set((nukes + "/damaged-places/targets[city='London']/city").c_str(), "London"); |
| 864 | buf->val(i++)->set((nukes + "/damaged-places/targets[city='Berlin']/city").c_str(), "Berlin"); |
| 865 | } |
| 866 | return SR_ERR_OK; |
| 867 | } |
| 868 | throw std::runtime_error("unrecognized RPC"); |
| 869 | } |
| 870 | }; |
| 871 | |
| 872 | TEST_CASE("rpc") { |
| 873 | trompeloeil::sequence seq1; |
| 874 | auto srConn = std::make_shared<sysrepo::Connection>("netconf-cli-test-rpc"); |
| 875 | auto srSession = std::make_shared<sysrepo::Session>(srConn); |
| 876 | auto srSubscription = std::make_shared<sysrepo::Subscribe>(srSession); |
| 877 | auto cb = std::make_shared<RpcCb>(); |
| 878 | sysrepo::Logs{}.set_stderr(SR_LL_INF); |
| 879 | srSubscription->rpc_subscribe("/example-schema:noop", cb, nullptr, SR_SUBSCR_CTX_REUSE); |
| 880 | srSubscription->rpc_subscribe("/example-schema:launch-nukes", cb, nullptr, SR_SUBSCR_CTX_REUSE); |
| 881 | |
| 882 | #ifdef sysrepo_BACKEND |
Václav Kubernát | 715c85c | 2020-04-14 01:46:08 +0200 | [diff] [blame] | 883 | SysrepoAccess datastore("netconf-cli-test", Datastore::Running); |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 884 | #elif defined(netconf_BACKEND) |
| 885 | NetconfAccess datastore(NETOPEER_SOCKET_PATH); |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 886 | #elif defined(yang_BACKEND) |
| 887 | YangAccess datastore; |
| 888 | datastore.addSchemaDir(schemaDir); |
| 889 | datastore.addSchemaFile(exampleSchemaFile); |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 890 | #else |
| 891 | #error "Unknown backend" |
| 892 | #endif |
| 893 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 894 | SECTION("valid") |
| 895 | { |
| 896 | std::string rpc; |
| 897 | DatastoreAccess::Tree input, output; |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 898 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 899 | SECTION("noop") { |
| 900 | rpc = "/example-schema:noop"; |
| 901 | } |
| 902 | |
| 903 | SECTION("small nuke") { |
| 904 | rpc = "/example-schema:launch-nukes"; |
| 905 | input = { |
| 906 | {"description", "dummy"s}, |
| 907 | {"payload/kilotons", uint64_t{333'666}}, |
| 908 | }; |
| 909 | // no data are returned |
| 910 | } |
| 911 | |
| 912 | SECTION("small nuke") { |
| 913 | rpc = "/example-schema:launch-nukes"; |
| 914 | input = { |
| 915 | {"description", "dummy"s}, |
| 916 | {"payload/kilotons", uint64_t{4}}, |
| 917 | }; |
| 918 | output = { |
| 919 | {"blast-radius", uint32_t{33'666}}, |
| 920 | {"actual-yield", uint64_t{5}}, |
| 921 | }; |
| 922 | } |
| 923 | |
| 924 | SECTION("with lists") { |
| 925 | rpc = "/example-schema:launch-nukes"; |
| 926 | input = { |
| 927 | {"payload/kilotons", uint64_t{6}}, |
| 928 | {"cities/targets[city='Prague']/city", "Prague"s}, |
| 929 | }; |
| 930 | output = { |
| 931 | {"blast-radius", uint32_t{33'666}}, |
| 932 | {"actual-yield", uint64_t{7}}, |
| 933 | {"damaged-places", special_{SpecialValue::PresenceContainer}}, |
| 934 | {"damaged-places/targets[city='London']", special_{SpecialValue::List}}, |
| 935 | {"damaged-places/targets[city='London']/city", "London"s}, |
| 936 | {"damaged-places/targets[city='Berlin']", special_{SpecialValue::List}}, |
| 937 | {"damaged-places/targets[city='Berlin']/city", "Berlin"s}, |
| 938 | }; |
| 939 | } |
| 940 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 941 | catching<OnRPC>([&] {REQUIRE(datastore.executeRpc(rpc, input) == output);}); |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 942 | } |
| 943 | |
Jan Kundrát | 7ec214d | 2020-06-19 17:05:07 +0200 | [diff] [blame] | 944 | SECTION("non-existing RPC") |
| 945 | { |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 946 | catching<OnInvalidRpcPath>([&] {datastore.executeRpc("/example-schema:non-existing", DatastoreAccess::Tree{});}); |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Jan Kundrát | 6ee8479 | 2020-01-24 01:43:36 +0100 | [diff] [blame] | 949 | waitForCompletionAndBitMore(seq1); |
| 950 | } |