Skip to content

Commit

Permalink
Add tests for Aviso/Mirror parser
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbento committed Jun 3, 2024
1 parent 0cfd4b0 commit dc46763
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ set(test_srcs
test/parser/PersistHelper.cpp
test/parser/TemporaryFile.cpp
test/parser/TestAutoAddExterns.cpp
test/parser/TestAvisoAttr.cpp
test/parser/TestDefsStructurePersistAndReload.cpp
test/parser/TestMementoPersistAndReload.cpp
test/parser/TestMigration.cpp
test/parser/TestMirrorAttr.cpp
test/parser/TestParser.cpp
test/parser/TestParser_main.cpp # test entry point
test/parser/TestVariableParsing.cpp
Expand Down
110 changes: 110 additions & 0 deletions libs/node/test/parser/TestAvisoAttr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2009- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/

#include <iostream>
#include <string>

#include <boost/test/unit_test.hpp>

#include "ecflow/node/AvisoAttr.hpp"
#include "ecflow/node/Defs.hpp"
#include "ecflow/node/Family.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/node/parser/DefsStructureParser.hpp"

BOOST_AUTO_TEST_SUITE(U_Parser)

BOOST_AUTO_TEST_SUITE(T_AvisoAttr)

BOOST_AUTO_TEST_CASE(can_parse_aviso_attribute_on_task_with_default_parameters) {
std::cout << "..." << boost::unit_test::framework::current_test_unit().full_name() << std::endl;

using namespace ecf;

std::string definition = R"(
suite s1
family f1
task t1
aviso --name A --listener '{ "event": "mars", "request": { "class": "od"} }'
endfamily
)";

Defs defs;
DefsStructureParser parser(&defs, definition, true);

std::string errorMsg, warningMsg;
bool parsedOK = parser.doParse(errorMsg, warningMsg);
BOOST_CHECK_MESSAGE(parsedOK, "Failed to parse definition: " << errorMsg);

const auto& suites = defs.suiteVec();
BOOST_CHECK_EQUAL(suites.size(), static_cast<size_t>(1));

const auto& families = suites[0]->familyVec();
BOOST_CHECK_EQUAL(families.size(), static_cast<size_t>(1));

const auto& tasks = families[0]->taskVec();
BOOST_CHECK_EQUAL(tasks.size(), static_cast<size_t>(1));

const auto& avisos = tasks[0]->avisos();
BOOST_CHECK_EQUAL(avisos.size(), static_cast<size_t>(1));

const auto& aviso = avisos[0];
BOOST_CHECK_EQUAL(aviso.name(), "A");
BOOST_CHECK_EQUAL(aviso.listener(), R"('{ "event": "mars", "request": { "class": "od"} }')");
BOOST_CHECK_EQUAL(aviso.url(), "%ECF_AVISO_URL%");
BOOST_CHECK_EQUAL(aviso.schema(), "%ECF_AVISO_SCHEMA%");
BOOST_CHECK_EQUAL(aviso.auth(), "%ECF_AVISO_AUTH%");
BOOST_CHECK_EQUAL(aviso.polling(), "%ECF_AVISO_POLLING%");
}

BOOST_AUTO_TEST_CASE(can_parse_aviso_attribute_on_task_with_all_parameters) {
std::cout << "..." << boost::unit_test::framework::current_test_unit().full_name() << std::endl;

using namespace ecf;

std::string definition = R"(
suite s1
family f1
task t1
aviso --name A --listener '{ "event": "mars", "request": { "class": "od"} }' --url http://host:port --schema /path/to/schema --auth /path/to/auth --polling 60
endfamily
)";

Defs defs;
DefsStructureParser parser(&defs, definition, true);

std::string errorMsg, warningMsg;
bool parsedOK = parser.doParse(errorMsg, warningMsg);
BOOST_CHECK_MESSAGE(parsedOK, "Failed to parse definition: " << errorMsg);

const auto& suites = defs.suiteVec();
BOOST_CHECK_EQUAL(suites.size(), static_cast<size_t>(1));

const auto& families = suites[0]->familyVec();
BOOST_CHECK_EQUAL(families.size(), static_cast<size_t>(1));

const auto& tasks = families[0]->taskVec();
BOOST_CHECK_EQUAL(tasks.size(), static_cast<size_t>(1));

const auto& avisos = tasks[0]->avisos();
BOOST_CHECK_EQUAL(avisos.size(), static_cast<size_t>(1));

const auto& aviso = avisos[0];
BOOST_CHECK_EQUAL(aviso.name(), "A");
BOOST_CHECK_EQUAL(aviso.listener(), R"('{ "event": "mars", "request": { "class": "od"} }')");
BOOST_CHECK_EQUAL(aviso.url(), "http://host:port");
BOOST_CHECK_EQUAL(aviso.schema(), "/path/to/schema");
BOOST_CHECK_EQUAL(aviso.auth(), "/path/to/auth");
BOOST_CHECK_EQUAL(aviso.polling(), "60");
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
110 changes: 110 additions & 0 deletions libs/node/test/parser/TestMirrorAttr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2009- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/

#include <iostream>
#include <string>

#include <boost/test/unit_test.hpp>

#include "ecflow/node/Defs.hpp"
#include "ecflow/node/Family.hpp"
#include "ecflow/node/MirrorAttr.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/node/parser/DefsStructureParser.hpp"

BOOST_AUTO_TEST_SUITE(U_Parser)

BOOST_AUTO_TEST_SUITE(T_MirrorAttr)

BOOST_AUTO_TEST_CASE(can_parse_mirror_attribute_on_task_with_default_parameters) {
std::cout << "..." << boost::unit_test::framework::current_test_unit().full_name() << std::endl;

using namespace ecf;

std::string definition = R"(
suite s1
family f1
task t1
mirror --name A --remote_path /s1/f1/t2
endfamily
)";

Defs defs;
DefsStructureParser parser(&defs, definition, true);

std::string errorMsg, warningMsg;
bool parsedOK = parser.doParse(errorMsg, warningMsg);
BOOST_CHECK_MESSAGE(parsedOK, "Failed to parse definition: " << errorMsg);

const auto& suites = defs.suiteVec();
BOOST_CHECK_EQUAL(suites.size(), static_cast<size_t>(1));

const auto& families = suites[0]->familyVec();
BOOST_CHECK_EQUAL(families.size(), static_cast<size_t>(1));

const auto& tasks = families[0]->taskVec();
BOOST_CHECK_EQUAL(tasks.size(), static_cast<size_t>(1));

const auto& mirrors = tasks[0]->mirrors();
BOOST_CHECK_EQUAL(mirrors.size(), static_cast<size_t>(1));

const auto& mirror = mirrors[0];
BOOST_CHECK_EQUAL(mirror.name(), "A");
BOOST_CHECK_EQUAL(mirror.remote_path(), "/s1/f1/t2");
BOOST_CHECK_EQUAL(mirror.remote_host(), "%ECF_MIRROR_REMOTE_HOST%");
BOOST_CHECK_EQUAL(mirror.remote_port(), "%ECF_MIRROR_REMOTE_PORT%");
BOOST_CHECK_EQUAL(mirror.polling(), "%ECF_MIRROR_REMOTE_POLLING%");
BOOST_CHECK_EQUAL(mirror.ssl(), false);
}

BOOST_AUTO_TEST_CASE(can_parse_mirror_attribute_on_task_with_all_attributes) {
std::cout << "..." << boost::unit_test::framework::current_test_unit().full_name() << std::endl;

using namespace ecf;

std::string definition = R"(
suite s1
family f1
task t1
mirror --name A --remote_path /s1/f1/t2 --remote_host hostname --remote_port 1234 --polling 20 --ssl
endfamily
)";

Defs defs;
DefsStructureParser parser(&defs, definition, true);

std::string errorMsg, warningMsg;
bool parsedOK = parser.doParse(errorMsg, warningMsg);
BOOST_CHECK_MESSAGE(parsedOK, "Failed to parse definition: " << errorMsg);

const auto& suites = defs.suiteVec();
BOOST_CHECK_EQUAL(suites.size(), static_cast<size_t>(1));

const auto& families = suites[0]->familyVec();
BOOST_CHECK_EQUAL(families.size(), static_cast<size_t>(1));

const auto& tasks = families[0]->taskVec();
BOOST_CHECK_EQUAL(tasks.size(), static_cast<size_t>(1));

const auto& mirrors = tasks[0]->mirrors();
BOOST_CHECK_EQUAL(mirrors.size(), static_cast<size_t>(1));

const auto& mirror = mirrors[0];
BOOST_CHECK_EQUAL(mirror.name(), "A");
BOOST_CHECK_EQUAL(mirror.remote_path(), "/s1/f1/t2");
BOOST_CHECK_EQUAL(mirror.remote_host(), "hostname");
BOOST_CHECK_EQUAL(mirror.remote_port(), "1234");
BOOST_CHECK_EQUAL(mirror.polling(), "20");
BOOST_CHECK_EQUAL(mirror.ssl(), true);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
24 changes: 24 additions & 0 deletions libs/node/test/parser/data/good_defs/aviso/aviso.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
suite aviso
edit ECF_HOME '/Users/mamb/w/sandbox.aviso/.'
edit ECF_INCLUDE '/Users/mamb/w/sandbox.aviso/core/included'
edit ECF_FILES '/Users/mamb/w/sandbox.aviso/scripts'
edit ECF_AVISO_URL 'http://localhost:2379'
edit ECF_AVISO_SCHEMA '/Users/mamb/w/sandbox.aviso/client/service_configuration/event_listener_schema.json'
edit ECF_AVISO_POLLING '40'
edit ECF_AVISO_AUTH '/Users/mamb/w/sandbox.aviso/aviso.auth'
family f1
task t1
aviso --name A --listener '{ "event": "mars", "request": { "class": "od", "expver": "0001", "domain": "g", "stream": "enfo", "step": [0, 6, 12, 18] } }' --url %ECF_AVISO_URL% --schema %ECF_AVISO_SCHEMA% --auth %ECF_AVISO_AUTH% --polling %ECF_AVISO_POLLING%
task t2
aviso --name B --listener '{ "event": "mars", "request": { "class": "od", "expver": "0001", "domain": "g", "stream": "enfo", "step": [0, 6] } }' --url %ECF_AVISO_URL% --schema %ECF_AVISO_SCHEMA% --polling %ECF_AVISO_POLLING%
task t3
aviso --name D --listener '{ "event": "mars", "request": { "class": "od", "expver": "0001", "domain": "g", "stream": "enfo", "step": [0, 12] } }' --url %ECF_AVISO_URL% --schema %ECF_AVISO_SCHEMA% --polling %ECF_AVISO_POLLING%
task t4
aviso --name E --listener '{ "event": "dissemination", "request": { "destination": "COM" } }' --url %ECF_AVISO_URL% --schema %ECF_AVISO_SCHEMA% --polling 20
task t5
aviso --name F --listener '{ "event": "dissemination", "request": { "destination": "ABC" } }' --url %ECF_AVISO_URL% --schema %ECF_AVISO_SCHEMA% --polling 20
task tX
edit ECF_AVISO_URL 'http://wrong:2379'
aviso --name X --listener '{ "event": "mars", "request": { "class": "od", "expver": "0001", "domain": "g", "stream": "enfo", "step": [0, 6, 12, 18] } }' --url %ECF_AVISO_URL% --schema %ECF_AVISO_SCHEMA% --polling %ECF_AVISO_POLLING%
endfamily
endsuite
19 changes: 19 additions & 0 deletions libs/node/test/parser/data/good_defs/mirror/mirror.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
suite mirror
edit ECF_HOME '/Users/mamb/w/sandbox.aviso/.'
edit ECF_INCLUDE '/Users/mamb/w/sandbox.aviso/core/included'
edit ECF_FILES '/Users/mamb/w/sandbox.aviso/scripts'
family f1
edit ECF_MIRROR_REMOTE_HOST 'localhost'
edit ECF_MIRROR_REMOTE_PORT '1234'
edit ECF_MIRROR_REMOTE_POLLING '21'
edit ECF_MIRROR_REMOTE_AUTH '/Users/mamb/w/sandbox.aviso/mirror.auth'
task t1
mirror --name operationsX --remote_path /s1/f1/t1 --ssl
task t2
mirror --name operationsY --remote_path /s1/f1/t2 --remote_host %ECF_MIRROR_REMOTE_HOST% --polling 20 --remote_port %ECF_MIRROR_REMOTE_PORT% --ssl
task t3
mirror --name operationsZ --remote_path /s1/f1/t3 --polling 20 --remote_host %ECF_MIRROR_REMOTE_HOST% --remote_port %ECF_MIRROR_REMOTE_PORT% --ssl
task t4
trigger t1 == complete and t2 == complete and t3 == complete
endfamily
endsuite

0 comments on commit dc46763

Please sign in to comment.