From dc46763df273222742b8f3409c1037986d2cb6db Mon Sep 17 00:00:00 2001 From: Marcos Bento Date: Mon, 3 Jun 2024 10:47:13 +0100 Subject: [PATCH] Add tests for Aviso/Mirror parser --- libs/node/CMakeLists.txt | 2 + libs/node/test/parser/TestAvisoAttr.cpp | 110 ++++++++++++++++++ libs/node/test/parser/TestMirrorAttr.cpp | 110 ++++++++++++++++++ .../parser/data/good_defs/aviso/aviso.def | 24 ++++ .../parser/data/good_defs/mirror/mirror.def | 19 +++ 5 files changed, 265 insertions(+) create mode 100644 libs/node/test/parser/TestAvisoAttr.cpp create mode 100644 libs/node/test/parser/TestMirrorAttr.cpp create mode 100644 libs/node/test/parser/data/good_defs/aviso/aviso.def create mode 100644 libs/node/test/parser/data/good_defs/mirror/mirror.def diff --git a/libs/node/CMakeLists.txt b/libs/node/CMakeLists.txt index 0f0d552ec..ccd2488d2 100644 --- a/libs/node/CMakeLists.txt +++ b/libs/node/CMakeLists.txt @@ -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 diff --git a/libs/node/test/parser/TestAvisoAttr.cpp b/libs/node/test/parser/TestAvisoAttr.cpp new file mode 100644 index 000000000..1255e7d54 --- /dev/null +++ b/libs/node/test/parser/TestAvisoAttr.cpp @@ -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 +#include + +#include + +#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(1)); + + const auto& families = suites[0]->familyVec(); + BOOST_CHECK_EQUAL(families.size(), static_cast(1)); + + const auto& tasks = families[0]->taskVec(); + BOOST_CHECK_EQUAL(tasks.size(), static_cast(1)); + + const auto& avisos = tasks[0]->avisos(); + BOOST_CHECK_EQUAL(avisos.size(), static_cast(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(1)); + + const auto& families = suites[0]->familyVec(); + BOOST_CHECK_EQUAL(families.size(), static_cast(1)); + + const auto& tasks = families[0]->taskVec(); + BOOST_CHECK_EQUAL(tasks.size(), static_cast(1)); + + const auto& avisos = tasks[0]->avisos(); + BOOST_CHECK_EQUAL(avisos.size(), static_cast(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() diff --git a/libs/node/test/parser/TestMirrorAttr.cpp b/libs/node/test/parser/TestMirrorAttr.cpp new file mode 100644 index 000000000..3d0a13ad8 --- /dev/null +++ b/libs/node/test/parser/TestMirrorAttr.cpp @@ -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 +#include + +#include + +#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(1)); + + const auto& families = suites[0]->familyVec(); + BOOST_CHECK_EQUAL(families.size(), static_cast(1)); + + const auto& tasks = families[0]->taskVec(); + BOOST_CHECK_EQUAL(tasks.size(), static_cast(1)); + + const auto& mirrors = tasks[0]->mirrors(); + BOOST_CHECK_EQUAL(mirrors.size(), static_cast(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(1)); + + const auto& families = suites[0]->familyVec(); + BOOST_CHECK_EQUAL(families.size(), static_cast(1)); + + const auto& tasks = families[0]->taskVec(); + BOOST_CHECK_EQUAL(tasks.size(), static_cast(1)); + + const auto& mirrors = tasks[0]->mirrors(); + BOOST_CHECK_EQUAL(mirrors.size(), static_cast(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() diff --git a/libs/node/test/parser/data/good_defs/aviso/aviso.def b/libs/node/test/parser/data/good_defs/aviso/aviso.def new file mode 100644 index 000000000..23c0d86d8 --- /dev/null +++ b/libs/node/test/parser/data/good_defs/aviso/aviso.def @@ -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 diff --git a/libs/node/test/parser/data/good_defs/mirror/mirror.def b/libs/node/test/parser/data/good_defs/mirror/mirror.def new file mode 100644 index 000000000..4c09e01a7 --- /dev/null +++ b/libs/node/test/parser/data/good_defs/mirror/mirror.def @@ -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