API
 
Loading...
Searching...
No Matches
xindiserver_test.cpp
Go to the documentation of this file.
1
2#include "../../../tests/catch2/catch.hpp"
3
4
5#include "../xindiserver.hpp"
6
7using namespace MagAOX::app;
8
9namespace MagAOX
10{
11namespace app
12{
14{
15 void indiserver_m( xindiserver & xi, const int &m) {xi.indiserver_m = m; }
16 void indiserver_n( xindiserver & xi, const bool &n) {xi.indiserver_n = n;}
17 void indiserver_p( xindiserver & xi, const int &p) {xi.indiserver_p = p;}
18 void indiserver_v( xindiserver & xi, const int &v) {xi.indiserver_v = v;}
19 void indiserver_x( xindiserver & xi, const bool &x) {xi.indiserver_x = x;}
20 void m_local(xindiserver & xi, const std::vector<std::string> & ml) {xi.m_local = ml;}
21 void m_remote(xindiserver & xi, const std::vector<std::string> & mr) {xi.m_remote = mr;}
22
24};
25}
26}
27
28
29SCENARIO( "xindiserver constructs inserver options", "[xindiserver]" )
30{
31 GIVEN("A default constructed xindiserver")
32 {
33 xindiserver xi;
34 xindiserver_test xi_test;
35
36 int rv;
37
38 WHEN("Option m with argument provided")
39 {
40 std::vector<std::string> clargs;
41 xi_test.indiserver_m(xi, 100);
42
43 rv = xi.constructIndiserverCommand(clargs);
44 REQUIRE(rv == 0);
45 REQUIRE(clargs.size() == 3);
46 REQUIRE(clargs[0] == "indiserver");
47 REQUIRE(clargs[1] == "-m");
48 REQUIRE(clargs[2] == "100");
49
50
51 }
52
53 WHEN("Option n provided")
54 {
55 std::vector<std::string> clargs;
56 xi_test.indiserver_n(xi, true);
57
58 rv = xi.constructIndiserverCommand(clargs);
59 REQUIRE(rv == 0);
60 REQUIRE(clargs.size() == 2);
61 REQUIRE(clargs[0] == "indiserver");
62 REQUIRE(clargs[1] == "-n");
63 }
64
65 WHEN("Option p provided with argument")
66 {
67 std::vector<std::string> clargs;
68 xi_test.indiserver_p(xi, 2000);
69
70 rv = xi.constructIndiserverCommand(clargs);
71 REQUIRE(rv == 0);
72 REQUIRE(clargs.size() == 3);
73 REQUIRE(clargs[0] == "indiserver");
74 REQUIRE(clargs[1] == "-p");
75 REQUIRE(clargs[2] == "2000");
76 }
77
78 WHEN("1 Option v provided with argument (-v)")
79 {
80 std::vector<std::string> clargs;
81 xi_test.indiserver_v(xi, 1);
82
83 rv = xi.constructIndiserverCommand(clargs);
84 REQUIRE(rv == 0);
85 REQUIRE(clargs.size() == 2);
86 REQUIRE(clargs[0] == "indiserver");
87 REQUIRE(clargs[1] == "-v");
88 }
89
90 WHEN("2 Option v provided with argument (-vv)")
91 {
92 std::vector<std::string> clargs;
93 xi_test.indiserver_v(xi, 2);
94
95 rv = xi.constructIndiserverCommand(clargs);
96 REQUIRE(rv == 0);
97 REQUIRE(clargs.size() == 2);
98 REQUIRE(clargs[0] == "indiserver");
99 REQUIRE(clargs[1] == "-vv");
100 }
101
102 WHEN("3 Option v provided with argument (3==>-vvv)")
103 {
104 std::vector<std::string> clargs;
105 xi_test.indiserver_v(xi, 3);
106
107 rv = xi.constructIndiserverCommand(clargs);
108 REQUIRE(rv == 0);
109 REQUIRE(clargs.size() == 2);
110 REQUIRE(clargs[0] == "indiserver");
111 REQUIRE(clargs[1] == "-vvv");
112 }
113
114 WHEN("Option v provided with argument (4==>-vvv)")
115 {
116 std::vector<std::string> clargs;
117 xi_test.indiserver_v(xi, 4);
118
119 rv = xi.constructIndiserverCommand(clargs);
120 REQUIRE(rv == 0);
121 REQUIRE(clargs.size() == 2);
122 REQUIRE(clargs[0] == "indiserver");
123 REQUIRE(clargs[1] == "-vvv");
124 }
125
126 WHEN("Option v provided with argument (0==>)")
127 {
128 std::vector<std::string> clargs;
129 xi_test.indiserver_v(xi, 0);
130
131 rv = xi.constructIndiserverCommand(clargs);
132 REQUIRE(rv == 0);
133 REQUIRE(clargs.size() == 1);
134 REQUIRE(clargs[0] == "indiserver");
135 }
136
137 WHEN("Option x provided")
138 {
139 std::vector<std::string> clargs;
140 xi_test.indiserver_x(xi, true);
141
142 rv = xi.constructIndiserverCommand(clargs);
143 REQUIRE(rv == 0);
144 REQUIRE(clargs.size() == 2);
145 REQUIRE(clargs[0] == "indiserver");
146 REQUIRE(clargs[1] == "-x");
147 }
148
149 WHEN("All options provided")
150 {
151 std::vector<std::string> clargs;
152 xi_test.indiserver_m(xi, 100);
153 xi_test.indiserver_n(xi, true);
154 xi_test.indiserver_p(xi, 2000);
155 xi_test.indiserver_v(xi, 2);
156 xi_test.indiserver_x(xi, true);
157
158 rv = xi.constructIndiserverCommand(clargs);
159 REQUIRE(rv == 0);
160 REQUIRE(clargs.size() == 8);
161 REQUIRE(clargs[0] == "indiserver");
162 REQUIRE(clargs[1] == "-m");
163 REQUIRE(clargs[2] == "100");
164 REQUIRE(clargs[3] == "-n");
165 REQUIRE(clargs[4] == "-p");
166 REQUIRE(clargs[5] == "2000");
167 REQUIRE(clargs[6] == "-vv");
168 REQUIRE(clargs[7] == "-x");
169 }
170 }
171}
172
173SCENARIO( "xindiserver constructs local driver arguments", "[xindiserver]" )
174{
175 GIVEN("A default constructed xindiserver")
176 {
177 xindiserver xi;
178 xindiserver_test xi_test;
179
180 int rv;
181
182 WHEN("Single local driver")
183 {
184 std::vector<std::string> ml({"driverX"});
185 xi_test.m_local(xi, ml);
186
187 std::vector<std::string> clargs;
188 rv = xi.addLocalDrivers(clargs);
189 REQUIRE(rv == 0);
190 REQUIRE(clargs.size() == 1);
191 REQUIRE(clargs[0] == "/opt/MagAOX/drivers/driverX");
192 }
193
194 WHEN("Two local drivers")
195 {
196 std::vector<std::string> ml({"driverY","driverZ"});
197 xi_test.m_local(xi, ml);
198
199 std::vector<std::string> clargs;
200 rv = xi.addLocalDrivers(clargs);
201 REQUIRE(rv == 0);
202 REQUIRE(clargs.size() == 2);
203 REQUIRE(clargs[0] == "/opt/MagAOX/drivers/driverY");
204 REQUIRE(clargs[1] == "/opt/MagAOX/drivers/driverZ");
205 }
206
207 WHEN("Three local drivers")
208 {
209 std::vector<std::string> ml({"driverX","driverY", "driverZ"});
210 xi_test.m_local(xi, ml);
211
212 std::vector<std::string> clargs;
213 rv = xi.addLocalDrivers(clargs);
214 REQUIRE(rv == 0);
215 REQUIRE(clargs.size() == 3);
216 REQUIRE(clargs[0] == "/opt/MagAOX/drivers/driverX");
217 REQUIRE(clargs[1] == "/opt/MagAOX/drivers/driverY");
218 REQUIRE(clargs[2] == "/opt/MagAOX/drivers/driverZ");
219 }
220
221 WHEN("Three local drivers, with an error (@)")
222 {
223 std::vector<std::string> ml({"driverX","driver@Y", "driverZ"});
224 xi_test.m_local(xi, ml);
225
226 std::vector<std::string> clargs;
227 rv = xi.addLocalDrivers(clargs);
229 }
230
231 WHEN("Three local drivers, with an error (/)")
232 {
233 std::vector<std::string> ml({"driver/X","driverY", "driverZ"});
234 xi_test.m_local(xi, ml);
235
236 std::vector<std::string> clargs;
237 rv = xi.addLocalDrivers(clargs);
239 }
240
241 WHEN("Three local drivers, with an error (:)")
242 {
243 std::vector<std::string> ml({"driverX","driverY", "driver:Z"});
244 xi_test.m_local(xi, ml);
245
246 std::vector<std::string> clargs;
247 rv = xi.addLocalDrivers(clargs);
249 }
250
251 WHEN("Three local drivers, duplicate")
252 {
253 std::vector<std::string> ml({"driverX","driverY", "driverX"});
254 xi_test.m_local(xi, ml);
255
256 std::vector<std::string> clargs;
257 rv = xi.addLocalDrivers(clargs);
259 }
260 }
261}
262
263SCENARIO( "xindiserver constructs remote driver arguments", "[xindiserver]" )
264{
265 GIVEN("A default constructed xindiserver")
266 {
267 xindiserver xi;
268 xindiserver_test xi_test;
269
270 int rv;
271
272 WHEN("Single remote driver, single remote host")
273 {
274 std::vector<std::string> mr({"driverX@host1"});
275 xi_test.m_remote(xi, mr);
276
277 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1" },
278 {"remoteHost", "localPort", "remotePort" },
279 {"host1", "1000", "81" } );
280 mx::app::appConfigurator config;
281 config.readConfig("/tmp/xindiserver_test.conf");
282
283 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
284
285 std::vector<std::string> clargs;
286 rv = xi.addRemoteDrivers(clargs);
287 REQUIRE(rv == 0);
288 REQUIRE(clargs.size() == 1);
289 REQUIRE(clargs[0] == "driverX@localhost:1000");
290 }
291
292 WHEN("Two remote drivers, single remote host")
293 {
294 std::vector<std::string> mr({"driverX@host1","driverY@host1"});
295 xi_test.m_remote(xi, mr);
296
297 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1" },
298 {"remoteHost", "localPort", "remotePort" },
299 {"host1", "1000", "81" } );
300 mx::app::appConfigurator config;
301 config.readConfig("/tmp/xindiserver_test.conf");
302
303 xi_test.tunnelMap(xi).clear(); //make sure we don't hold over
304 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
305
306 std::vector<std::string> clargs;
307 rv = xi.addRemoteDrivers(clargs);
308 REQUIRE(rv == 0);
309 REQUIRE(clargs.size() == 2);
310 REQUIRE(clargs[0] == "driverX@localhost:1000");
311 REQUIRE(clargs[1] == "driverY@localhost:1000");
312 }
313
314
315 WHEN("Two remote drivers, two remote hosts")
316 {
317 std::vector<std::string> mr({"driverX@host1","driverY@host2"});
318 xi_test.m_remote(xi, mr);
319
320 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1", "host2", "host2", "host2" },
321 {"remoteHost", "localPort", "remotePort","remoteHost", "localPort", "remotePort" },
322 {"host1", "1000", "81" ,"host2", "1002", "86"} );
323 mx::app::appConfigurator config;
324 config.readConfig("/tmp/xindiserver_test.conf");
325
326 xi_test.tunnelMap(xi).clear(); //make sure we don't hold over
327 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
328
329 std::vector<std::string> clargs;
330 rv = xi.addRemoteDrivers(clargs);
331 REQUIRE(rv == 0);
332 REQUIRE(clargs.size() == 2);
333 REQUIRE(clargs[0] == "driverX@localhost:1000");
334 REQUIRE(clargs[1] == "driverY@localhost:1002");
335 }
336
337
338 WHEN("Three remote drivers, two remote hosts, in order")
339 {
340 std::vector<std::string> mr({"driverX@host1","driverZ@host1", "driverY@host2"});
341 xi_test.m_remote(xi, mr);
342
343 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1", "host2", "host2", "host2" },
344 {"remoteHost", "localPort", "remotePort","remoteHost", "localPort", "remotePort" },
345 {"host1", "1000", "81" ,"host2", "1002", "86"} );
346
347 mx::app::appConfigurator config;
348 config.readConfig("/tmp/xindiserver_test.conf");
349
350 xi_test.tunnelMap(xi).clear(); //make sure we don't hold over
351 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
352
353 std::vector<std::string> clargs;
354 rv = xi.addRemoteDrivers(clargs);
355 REQUIRE(rv == 0);
356 REQUIRE(clargs.size() == 3);
357
358 REQUIRE(clargs[0] == "driverX@localhost:1000");
359 REQUIRE(clargs[1] == "driverZ@localhost:1000");
360 REQUIRE(clargs[2] == "driverY@localhost:1002");
361 }
362
363
364 WHEN("Three remote drivers, two remote hosts, arb order")
365 {
366 std::vector<std::string> mr({"driverX@host1","driverZ@host2", "driverY@host1"});
367 xi_test.m_remote(xi, mr);
368
369 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1", "host2", "host2", "host2" },
370 {"remoteHost", "localPort", "remotePort","remoteHost", "localPort", "remotePort" },
371 {"host1", "1000", "81" ,"host2", "1002", "86"} );
372
373 mx::app::appConfigurator config;
374 config.readConfig("/tmp/xindiserver_test.conf");
375
376 xi_test.tunnelMap(xi).clear(); //make sure we don't hold over
377 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
378
379 std::vector<std::string> clargs;
380 rv = xi.addRemoteDrivers(clargs);
381 REQUIRE(rv == 0);
382 REQUIRE(clargs.size() == 3);
383
384 REQUIRE(clargs[0] == "driverX@localhost:1000");
385 REQUIRE(clargs[1] == "driverZ@localhost:1002");
386 REQUIRE(clargs[2] == "driverY@localhost:1000");
387 }
388
389 WHEN("Three remote drivers, two remote hosts, error in host")
390 {
391 std::vector<std::string> mr({"driverX@host1","driverZ@host2", "driverY@host1"});
392 xi_test.m_remote(xi, mr);
393
394 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1", "host2", "host2" },
395 {"remoteHost", "localPort", "remotePort","remoteHost", "localPort" },
396 {"exao2", "1000", "81" ,"exao2", "1002"} );
397
398 mx::app::appConfigurator config;
399 config.readConfig("/tmp/xindiserver_test.conf");
400
401 xi_test.tunnelMap(xi).clear(); //make sure we don't hold over
402 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
403
404 std::vector<std::string> clargs;
405 rv = xi.addRemoteDrivers(clargs);
407 }
408
409 WHEN("Three remote drivers, two remote hosts, error in driver")
410 {
411 std::vector<std::string> mr({"driverX","driverZ@host2", "driverY@host1"});
412 xi_test.m_remote(xi, mr);
413
414 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1", "host2", "host2", "host2" },
415 {"remoteHost", "localPort", "remotePort","remoteHost", "localPort", "remotePort" },
416 {"host1", "1000", "81" ,"host2", "1002", "86"} );
417
418 mx::app::appConfigurator config;
419 config.readConfig("/tmp/xindiserver_test.conf");
420
421 xi_test.tunnelMap(xi).clear(); //make sure we don't hold over
422 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
423
424 std::vector<std::string> clargs;
425 rv = xi.addRemoteDrivers(clargs);
427 }
428
429 WHEN("Three remote drivers, two remote hosts, duplicate driver")
430 {
431 std::vector<std::string> mr({"driverX@host2","driverX@host1", "driverY@host1"});
432 xi_test.m_remote(xi, mr);
433
434 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1", "host2", "host2", "host2" },
435 {"remoteHost", "localPort", "remotePort","remoteHost", "localPort", "remotePort" },
436 {"host1", "1000", "81" ,"host2", "1002", "86"} );
437
438 mx::app::appConfigurator config;
439 config.readConfig("/tmp/xindiserver_test.conf");
440 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
441
442 std::vector<std::string> clargs;
443 rv = xi.addRemoteDrivers(clargs);
445 }
446 }
447}
448
449SCENARIO( "xindiserver constructs both local and remote driver arguments", "[xindiserver]" )
450{
451 GIVEN("A default constructed xindiserver")
452 {
453 xindiserver xi;
454 xindiserver_test xi_test;
455
456 int rv;
457
458 WHEN("single local driver, single remote driver, single remote host")
459 {
460
461 std::vector<std::string> ml({"driverX"});
462 xi_test.m_local(xi, ml);
463
464 std::vector<std::string> mr({"driverY@host1"});
465 xi_test.m_remote(xi, mr);
466
467 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1" },
468 {"remoteHost", "localPort", "remotePort" },
469 {"host1", "1000", "81" } );
470 mx::app::appConfigurator config;
471 config.readConfig("/tmp/xindiserver_test.conf");
472
473 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
474
475 std::vector<std::string> clargs;
476 rv = xi.addRemoteDrivers(clargs);
477 REQUIRE(rv == 0);
478
479 rv = xi.addLocalDrivers(clargs);
480 REQUIRE(rv == 0);
481
482 REQUIRE(clargs.size() == 2);
483
484
485 REQUIRE(clargs[0] == "driverY@localhost:1000");
486 REQUIRE(clargs[1] == "/opt/MagAOX/drivers/driverX");
487 }
488
489 WHEN("single local driver, single remote driver, single remote host -- duplicate driver")
490 {
491
492 std::vector<std::string> ml({"driverX"});
493 xi_test.m_local(xi, ml);
494
495 std::vector<std::string> mr({"driverX@host1"});
496 xi_test.m_remote(xi, mr);
497
498 mx::app::writeConfigFile( "/tmp/xindiserver_test.conf", {"host1", "host1", "host1" },
499 {"remoteHost", "localPort", "remotePort" },
500 {"host1", "1000", "81" } );
501 mx::app::appConfigurator config;
502 config.readConfig("/tmp/xindiserver_test.conf");
503
504 loadSSHTunnelConfigs( xi_test.tunnelMap(xi), config);
505
506 std::vector<std::string> clargs;
507 rv = xi.addRemoteDrivers(clargs);
508 REQUIRE(rv == 0);
509
510 rv = xi.addLocalDrivers(clargs);
512
513 }
514 }
515}
#define GIVEN(desc)
Definition catch.hpp:17763
#define WHEN(desc)
Definition catch.hpp:17765
#define SCENARIO(...)
Definition catch.hpp:17760
#define REQUIRE(...)
Definition catch.hpp:17676
int indiserver_m
The indiserver MB behind setting (passed to indiserver)
int addRemoteDrivers(std::vector< std::string > &driverArgs)
Validate the remote driver entries, and append them to the indi server command line arguments.
std::vector< std::string > m_local
List of local drivers passed in by config.
bool indiserver_n
The indiserver ignore /tmp/noindi flag (passed to indiserver)
int addLocalDrivers(std::vector< std::string > &driverArgs)
Validate the local driver strings, and append them to the indi server command line arguments.
bool indiserver_x
The indiserver terminate after last exit flag (passed to indiserver)
std::vector< std::string > m_remote
List of remote drivers passed in by config.
tunnelMapT m_tunnels
Map of the ssh tunnels, used for processing the remote drivers in m_remote.
int indiserver_v
The indiserver verbosity (passed to indiserver)
int indiserver_p
The indiserver port (passed to indiserver)
int constructIndiserverCommand(std::vector< std::string > &indiserverCommand)
Construct the vector of indiserver arguments for exec.
std::unordered_map< std::string, sshTunnel > tunnelMapT
The map used to hold tunnel specifications.
int loadSSHTunnelConfigs(tunnelMapT &tmap, mx::app::appConfigurator &config)
Create the tunnel map from a configurator.
Definition dm.hpp:24
void m_local(xindiserver &xi, const std::vector< std::string > &ml)
tunnelMapT & tunnelMap(xindiserver &xi)
void indiserver_n(xindiserver &xi, const bool &n)
void indiserver_p(xindiserver &xi, const int &p)
void indiserver_m(xindiserver &xi, const int &m)
void indiserver_v(xindiserver &xi, const int &v)
void indiserver_x(xindiserver &xi, const bool &x)
void m_remote(xindiserver &xi, const std::vector< std::string > &mr)
#define XINDISERVER_E_BADDRIVERSPEC
#define XINDISERVER_E_DUPLICATEDRIVER
#define XINDISERVER_E_TUNNELNOTFOUND