fix all test failures
Change-Id: Ia046734dca015f2ef99b23562f0b88c8f51e82af
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 2c82f67..7b806b7 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -163,16 +163,13 @@
// process PROBE requests: collect probe parameters
auto parameters = PROBE::decodeApplicationParameters(request.getApplicationParameters());
std::vector<PartialName> availableComponents;
- try {
for (auto& item : m_config.m_heuristic) {
auto names = item->assignName(parameters);
availableComponents.insert(availableComponents.end(), names.begin(), names.end());
}
- }
- catch (const std::exception& e) {
- _LOG_TRACE("Cannot parse probe parameters: " << e.what());
+ if (availableComponents.size() == 0) {
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::INVALID_PARAMETER,
- "Cannot parse probe parameters: " + std::string(e.what())));
+ "Cannot generate available names from parameters provided."));
return;
}
std::vector<Name> availableNames;
diff --git a/src/name-assignments/assignment-param.cpp b/src/name-assignments/assignment-param.cpp
index 56da436..890af34 100644
--- a/src/name-assignments/assignment-param.cpp
+++ b/src/name-assignments/assignment-param.cpp
@@ -21,7 +21,7 @@
for (const auto& item : m_nameFormat) {
auto it = std::find_if(params.begin(), params.end(),
[&](const std::tuple<std::string, std::string>& e) { return std::get<0>(e) == item; });
- if (it != params.end()) {
+ if (it != params.end() && !std::get<1>(*it).empty()) {
result.append(std::get<1>(*it));
}
else {
diff --git a/tests/unit-tests/name-assignment.t.cpp b/tests/unit-tests/name-assignment.t.cpp
index 83c492c..8c690f5 100644
--- a/tests/unit-tests/name-assignment.t.cpp
+++ b/tests/unit-tests/name-assignment.t.cpp
@@ -38,34 +38,34 @@
BOOST_AUTO_TEST_CASE(NameAssignmentParam)
{
AssignmentParam assignment("/abc/xyz");
- std::vector<std::tuple<std::string, std::string>> requirements;
- requirements.emplace_back("abc", "123");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 0);
- requirements.emplace_back("xyz", "789");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
- BOOST_CHECK_EQUAL(*assignment.assignName(requirements).begin(), Name("/123/789"));
- requirements.emplace_back("fake", "456");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
- BOOST_CHECK_EQUAL(*assignment.assignName(requirements).begin(), Name("/123/789"));
- requirements[1] = std::tuple<std::string, std::string>("xyz", "");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 0);
+ std::vector<std::tuple<std::string, std::string>> params;
+ params.emplace_back("abc", "123");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0);
+ params.emplace_back("xyz", "789");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1);
+ BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/123/789"));
+ params.emplace_back("fake", "456");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1);
+ BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/123/789"));
+ params[1] = std::tuple<std::string, std::string>("xyz", "");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0);
}
BOOST_AUTO_TEST_CASE(NameAssignmentHash)
{
- AssignmentHash assignment("/abe/xyz");
- std::vector<std::tuple<std::string, std::string>> requirements;
- requirements.emplace_back("abc", "123");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 0);
- requirements.emplace_back("xyz", "789");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).begin()->size(), 1);
- requirements.emplace_back("fake", "456");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).begin()->size(), 1);
- requirements[1] = std::tuple<std::string, std::string>("xyz", "");
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
- BOOST_CHECK_EQUAL(assignment.assignName(requirements).begin()->size(), 1);
+ AssignmentHash assignment("/abc/xyz");
+ std::vector<std::tuple<std::string, std::string>> params;
+ params.emplace_back("abc", "123");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0);
+ params.emplace_back("xyz", "789");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2);
+ params.emplace_back("fake", "456");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2);
+ params[1] = std::tuple<std::string, std::string>("xyz", "");
+ BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2);
}
BOOST_AUTO_TEST_SUITE_END()