9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
14 using namespace testing;
23 EXPECT_EQ(o.
host,
"");
24 EXPECT_EQ(o.
path,
"foo");
28 EXPECT_EQ(o.
host,
"");
29 EXPECT_EQ(o.
path,
"foo");
33 EXPECT_EQ(o.
host,
"host");
34 EXPECT_EQ(o.
path,
"~/files/file.fits");
38 EXPECT_EQ(o.
host,
"host");
39 EXPECT_EQ(o.
path,
"/path/to/file:with:colons.fits");
43 EXPECT_EQ(o.
host,
"host");
44 EXPECT_EQ(o.
path,
"/path/to/file:with:colons.fits");
58 using namespace nlohmann;
63 "fileId": "TEST.FILEID",
66 "origin": "dcs-host:/path/to/somefile.fits",
70 "selectionPatterns": [
78 "selectionPatterns": [
88 "type": "fitsKeywords",
93 "selectionPatterns": [
101 "type": "valueKeyword",
103 "value": "ESO-PARANAL"
106 "type": "valueKeyword",
111 "type": "valueKeyword",
113 "value": "OBJECT,SKY"
116 "type": "esoKeyword",
117 "name": "OCS TEMPL ID",
118 "value": "template-id"
121 "type": "literalKeyword",
122 "value": "COMMENT Example of a commentary keyword."
127 "type": "fitsKeywords",
133 "type": "esoKeyword",
134 "name": "TEL AIRM START",
138 "type": "esoKeyword",
139 "name": "TEL AIRM END",
147 "origin": "fcs-host:/path/to/somefile.fits",
151 "selectionPatterns": [
159 "selectionPatterns": [
177 EXPECT_EQ(spec.id, "TEST.ID");
183 ASSERT_EQ(spec.
target.
source->keyword_rules.size(), 2u);
184 auto const& transform = std::get<DpSpec::Transform>(spec.
target.
source->keyword_rules[0]);
185 ASSERT_EQ(transform.selection_patterns.size(), 1);
186 EXPECT_EQ(transform.selection_patterns[0],
"+e INS *");
187 EXPECT_EQ(transform.format,
"INS2 ");
188 auto const& filter = std::get<DpSpec::Filter>(spec.
target.
source->keyword_rules[1]);
189 EXPECT_THAT(filter.selection_patterns, ElementsAre(
"+e INS2 *",
"+v VALUEKW"));
191 ASSERT_EQ(3u, spec.
sources.size());
192 auto const& ocm_kws_var = spec.
sources[0];
193 ASSERT_TRUE(std::holds_alternative<DpSpec::SourceFitsKeywords>(ocm_kws_var));
194 auto const& tcs_kws_var = spec.
sources[1];
195 ASSERT_TRUE(std::holds_alternative<DpSpec::SourceFitsKeywords>(tcs_kws_var));
196 auto const& fcs_fits_var = spec.
sources[2];
197 ASSERT_TRUE(std::holds_alternative<DpSpec::SourceFitsFile>(fcs_fits_var));
198 auto const& ocm_kws = std::get<DpSpec::SourceFitsKeywords>(spec.
sources[0]);
199 auto const& tcs_kws = std::get<DpSpec::SourceFitsKeywords>(spec.
sources[1]);
200 auto const& fcs_fits = std::get<DpSpec::SourceFitsFile>(spec.
sources[2]);
203 EXPECT_EQ(ocm_kws.source_name,
"ocm");
204 ASSERT_EQ(ocm_kws.keyword_rules.size(), 1);
205 auto const& filter = std::get<DpSpec::Filter>(ocm_kws.keyword_rules[0]);
206 ASSERT_EQ(filter.selection_patterns.size(), 2);
207 EXPECT_THAT(filter.selection_patterns, ElementsAre(
"+e *",
"+v *"));
210 EXPECT_EQ(tcs_kws.source_name,
"tcs");
211 EXPECT_EQ(fcs_fits.source_name,
"fcs");
215 m_spec[
"target"].erase(
"targetSource");
220 m_spec.erase(
"sources");
225 m_spec[
"sources"] = nlohmann::json::array();
236 m_spec["target"].erase(
"fileId");
242 m_spec["target"][
"fileId"] = 0u;
245 MatchesRegex(R
"(.*\(/target/fileId\).*must be a string.*)"));
249 m_spec["sources"][0][
"keywords"][0][
"type"] =
"";
252 MatchesRegex(R
"(.*\(/sources/0/keywords/0/type\).*empty.*)"));
256 m_spec["sources"][0].erase(
"keywords");
261 m_spec["sources"][2].erase(
"keywordRules");
266 m_spec[
"target"].erase(
"source");
267 m_spec[
"sources"] = nlohmann::json::array();
274 m_spec["sources"][0][
"type"] =
"unknown";
281 m_spec["sources"][0] = 0;
288 m_spec["sources"] = 0;