ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
testReceivers.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_libjson
4 * @copyright
5 * (c) Copyright ESO 2023
6 * All Rights Reserved
7 * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
8 */
9#include <gmock/gmock.h>
10#include <gtest/gtest.h>
11
13
14using namespace testing;
15
16namespace daq::json {
17using Json = nlohmann::json;
18using JsonPointer = nlohmann::json_pointer<Json>;
19
20TEST(TestParseReceivers, EmptyReceiverList) {
21 using namespace nlohmann;
22 auto j = R"(
23 [
24 ]
25 )"_json;
27 ASSERT_EQ(l.size(), 0u);
28}
29
30TEST(TestParseReceivers, ValidReceiverList) {
31 using namespace nlohmann;
32 auto j = R"(
33 [
34 {
35 "type": "olasReceiver",
36 "host": "1.2.3.4",
37 "path": "/path/to/incoming"
38 }
39 ]
40 )"_json;
42 ASSERT_EQ(l.size(), 1u);
43 ASSERT_TRUE(std::holds_alternative<OlasReceiver>(l[0]));
44 auto const& r = std::get<OlasReceiver>(l[0]);
45 EXPECT_EQ(r.host, "1.2.3.4");
46 EXPECT_EQ(r.path, "/path/to/incoming/");
47}
48
49TEST(TestParseOlasReceiver, ValidOlasReceiverWithoutHost) {
50 using namespace nlohmann;
51 auto j = R"(
52 {
53 "type": "olasReceiver",
54 "path": "/path/to/incoming"
55 }
56 )"_json;
58 EXPECT_EQ(r.host, "");
59 EXPECT_EQ(r.path, "/path/to/incoming/");
60}
61
62TEST(TestParseOlasReceiver, ValidOlasReceiverWithOptions) {
63 using namespace nlohmann;
64 auto j = R"(
65 {
66 "type": "olasReceiver",
67 "path": "/path/to/incoming",
68 "options": {
69 "allowSymlink": false
70 }
71 }
72 )"_json;
74 EXPECT_EQ(r.host, "");
75 EXPECT_EQ(r.path, "/path/to/incoming/");
76 EXPECT_FALSE(r.options.allow_symlink);
77}
78
79
80TEST(TestParseOlasReceiver, MissingPathIsRejected) {
81 using namespace nlohmann;
82 auto j = R"(
83 {
84 "type": "olasReceiver",
85 "path": ""
86 }
87 )"_json;
88 EXPECT_THROW(ParseOlasReceiver(j, JsonPointer("/")), SchemaError);
89}
90
91TEST(TestParseOlasReceiver, RelativePathsShouldBeRejected) {
92 using namespace nlohmann;
93 auto j = R"(
94 {
95 "type": "olasReceiver",
96 "path": "relative/path/to/incoming"
97 }
98 )"_json;
99 EXPECT_THROW(ParseOlasReceiver(j, JsonPointer("/")), SchemaError);
100}
101
102TEST(TestRoundTripParsing, ReceiverList) {
103 using namespace nlohmann;
104 auto in = R"(
105 [
106 {
107 "type": "olasReceiver",
108 "host": "1.2.3.4",
109 "path": "/path/to/incoming/",
110 "options": {
111 "noSymlink": true
112 }
113 }
114 ]
115 )"_json;
117 ASSERT_EQ(l1.size(), 1u);
118
119 Json out;
120 to_json(out, l1);
122 EXPECT_EQ(l1, l2);
123}
124
125} // namespace daq::json
std::filesystem::path path
Absolute path to the OLAS "incoming directory" where DPM will drop files.
OlasReceiver ParseOlasReceiver(nlohmann::json const &json, nlohmann::json_pointer< nlohmann::json > const &breadcrumb)
nlohmann::json Json
nlohmann::json_pointer< Json > JsonPointer
std::vector< ReceiverTypes > ReceiverList
TEST(TestParseReceivers, EmptyReceiverList)
ReceiverTransferOptions options
ReceiverList ParseReceiverList(Json const &json, JsonPointer const &breadcrumb)
std::string host
DHS host where OLAS ingest files.
daq::json::TestParseStartDaqV2Spec _json
void to_json(nlohmann::json &out, KeywordFilter const &s)
Represents OlasReceiver JSON type used in StartDaqV2 and dpspec.
JSON Schema error.
Definition: schemaError.hpp:18
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")
ASSERT_EQ(meta.keyword_rules.size(), 1u)
ASSERT_TRUE(std::holds_alternative< OlasReceiver >(spec.receivers[0]))