-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update paths object to return array of path objects #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -564,53 +564,55 @@ | |||||||||||
} | ||||||||||||
|
||||||||||||
std::pair<json, std::string> lotman::Lot::get_lot_dirs(const bool recursive) { | ||||||||||||
json path_obj; | ||||||||||||
json path_arr = json::array(); | ||||||||||||
Check warning on line 567 in src/lotman_internal.cpp
|
||||||||||||
std::string path_query = "SELECT path, recursive FROM paths WHERE lot_name = ?;"; | ||||||||||||
//std::string recursive_query = "SELECT recursive FROM paths WHERE path = ? AND lot_name = ?;"; | ||||||||||||
std::map<std::string, std::vector<int>> path_query_str_map{{lot_name, {1}}}; | ||||||||||||
auto rp = lotman::Checks::SQL_get_matches_multi_col(path_query, 2, path_query_str_map); | ||||||||||||
if (!rp.second.empty()) { // There was an error | ||||||||||||
std::string int_err = rp.second; | ||||||||||||
std::string ext_err = "Failure on call to SQL_get_matches_multi_col: "; | ||||||||||||
return std::make_pair(path_obj, ext_err + int_err); | ||||||||||||
return std::make_pair(path_arr, ext_err + int_err); | ||||||||||||
} | ||||||||||||
|
||||||||||||
for (const auto &path_rec : rp.first) { // the path is at index 0, and the recursion of the path is at index 1 | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [lint] reported by reviewdog 🐶
Suggested change
|
||||||||||||
json path_obj_internal; | ||||||||||||
path_obj_internal["lot_name"] = this->lot_name; | ||||||||||||
path_obj_internal["recursive"] = static_cast<bool>(std::stoi(path_rec[1])); | ||||||||||||
Comment on lines
580
to
581
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [lint] reported by reviewdog 🐶
Suggested change
|
||||||||||||
path_obj[path_rec[0]] = path_obj_internal; | ||||||||||||
path_obj_internal["path"] = path_rec[0]; | ||||||||||||
path_arr.push_back(path_obj_internal); | ||||||||||||
} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [lint] reported by reviewdog 🐶
Suggested change
|
||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [lint] reported by reviewdog 🐶
Suggested change
|
||||||||||||
if (recursive) { // Not recursion of path, but recursion of dirs associated to a lot, ie the directories associated with lot proper's children | ||||||||||||
Check warning on line 586 in src/lotman_internal.cpp
|
||||||||||||
auto rp_vec_str = this->get_children(true); | ||||||||||||
if (!rp_vec_str.second.empty()) { // There was an error | ||||||||||||
std::string int_err = rp_vec_str.second; | ||||||||||||
std::string ext_err = "Failure to get children."; | ||||||||||||
return std::make_pair(json(), ext_err+int_err); | ||||||||||||
return std::make_pair(json::array(), ext_err+int_err); | ||||||||||||
} | ||||||||||||
for (const auto &child : recursive_children) { | ||||||||||||
std::map<std::string, std::vector<int>> child_path_query_str_map{{child.lot_name, {1}}}; | ||||||||||||
rp = lotman::Checks::SQL_get_matches_multi_col(path_query, 2, child_path_query_str_map); | ||||||||||||
if (!rp.second.empty()) { // There was an error | ||||||||||||
std::string int_err = rp.second; | ||||||||||||
std::string ext_err = "Failure on call to SQL_get_matches_multi_col: "; | ||||||||||||
return std::make_pair(path_obj, ext_err + int_err); | ||||||||||||
return std::make_pair(path_arr, ext_err + int_err); | ||||||||||||
} | ||||||||||||
|
||||||||||||
for (const auto &path_rec : rp.first) { | ||||||||||||
json path_obj_internal; | ||||||||||||
path_obj_internal["lot_name"] = child.lot_name; | ||||||||||||
path_obj_internal["recursive"] = static_cast<bool>(std::stoi(path_rec[1])); | ||||||||||||
path_obj[path_rec[0]] = path_obj_internal; | ||||||||||||
path_obj_internal["path"] = path_rec[0]; | ||||||||||||
path_arr.push_back(path_obj_internal); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
return std::make_pair(path_obj, ""); | ||||||||||||
return std::make_pair(path_arr, ""); | ||||||||||||
} | ||||||||||||
|
||||||||||||
std::pair<std::string, std::string> lotman::Lot::get_lot_from_dir(const std::string dir_path) { | ||||||||||||
Check warning on line 615 in src/lotman_internal.cpp
|
||||||||||||
std::string lot_name_query = "SELECT lot_name FROM paths WHERE path = ?;"; | ||||||||||||
std::map<std::string, std::vector<int>> query_map{{dir_path, {1}}}; | ||||||||||||
auto rp = lotman::Checks::SQL_get_matches(lot_name_query, query_map); | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -446,7 +446,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
free(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TEST_F(LotManTest, GetLotDirs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warning on line 449 in test/main.cpp
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Try to get a lot that doesn't exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
char *err_msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const char *non_existent_lot = "non_existent_lot"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -461,15 +461,28 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rv = lotman_get_lot_dirs(lot_name, recursive, &output, &err_msg2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASSERT_TRUE(rv == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::unique_ptr<char, decltype(&free)> output_ptr(output, &free); // Wrap output with a unique_ptr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json json_out = json::parse(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASSERT_TRUE(json_out["/1/2/3/4"]["lot_name"] == "lot4" && json_out["/1/2/3/4"]["recursive"] == true && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json_out["/345"]["lot_name"] == "lot4" && json_out["/345"]["recursive"] == true && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json_out["/456"]["lot_name"] == "lot5" && json_out["/456"]["recursive"] == false && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json_out["/567"]["lot_name"] == "lot5" && json_out["/567"]["recursive"] == true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
free(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (const auto &path_obj : json_out) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (path_obj["path"] == "/1/2/3/4" && path_obj["recursive"] == true && path_obj["lot_name"] == "lot4") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if (path_obj["path"] == "/345" && path_obj["recursive"] == true && path_obj["lot_name"] == "lot4") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if (path_obj["path"] == "/456" && path_obj["recursive"] == false && path_obj["lot_name"] == "lot5") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if (path_obj["path"] == "/567" && path_obj["recursive"] == true && path_obj["lot_name"] == "lot5") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASSERT_TRUE(false) << "Unexpected path object: " << output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [lint] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TEST_F(LotManTest, ContextTest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warning on line 485 in test/main.cpp
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Any actions that modify the properties of a lot must have proper auth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// These tests should all fail (context set to nonexistant owner) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -591,7 +604,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASSERT_TRUE(size == 7); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lotman_free_string_list(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warning on line 607 in test/main.cpp
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TEST_F(LotManTest, GetLotJSONTest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Try to get a lot that doesn't exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
char *err_msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -603,13 +616,14 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
char *err_msg2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rv = lotman_get_lot_as_json("lot3", true, &output, &err_msg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASSERT_TRUE(rv == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json output_JSON = json::parse(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
free(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json expected_output = R"({"children":["lot4","lot5"],"lot_name":"lot3","management_policy_attrs":{"creation_time":{"lot_name":"lot3","value":123.0},"dedicated_GB":{"lot_name":"sep_node","value":3.0},"deletion_time":{"lot_name":"lot3","value":333.0},"expiration_time":{"lot_name":"lot3","value":222.0},"max_num_objects":{"lot_name":"sep_node","value":10.0},"opportunistic_GB":{"lot_name":"lot2","value":1.5}},"owners":["not owner1","owner1"],"parents":["lot1","lot2","sep_node"],"paths":{"/1/2/3/4":{"lot_name":"lot4","recursive":true},"/345":{"lot_name":"lot4","recursive":true},"/456":{"lot_name":"lot5","recursive":false},"/567":{"lot_name":"lot5","recursive":true},"/another/path":{"lot_name":"lot3","recursive":true},"/foo/barr":{"lot_name":"lot3","recursive":true},"/updated/path":{"lot_name":"lot3","recursive":false}},"usage":{"GB_being_written":{"children_contrib":3.4,"self_contrib":0.0},"dedicated_GB":{"children_contrib":8.64,"self_contrib":0.0,"total":8.64},"num_objects":{"children_contrib":10.0,"self_contrib":0.0},"objects_being_written":{"children_contrib":7.0,"self_contrib":0.0},"opportunistic_GB":{"children_contrib":0.0,"self_contrib":0.0,"total":0.0},"total_GB":{"children_contrib":8.64,"self_contrib":0.0}}})"_json; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASSERT_TRUE(output_JSON == expected_output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
json expected_output = R"({"children":["lot4","lot5"],"lot_name":"lot3","management_policy_attrs":{"creation_time":{"lot_name":"lot3","value":123.0},"dedicated_GB":{"lot_name":"sep_node","value":3.0},"deletion_time":{"lot_name":"lot3","value":333.0},"expiration_time":{"lot_name":"lot3","value":222.0},"max_num_objects":{"lot_name":"sep_node","value":10.0},"opportunistic_GB":{"lot_name":"lot2","value":1.5}},"owners":["not owner1","owner1"],"parents":["lot1","lot2","sep_node"],"paths":[{"lot_name":"lot3","path":"/another/path","recursive":true},{"lot_name":"lot3","path":"/updated/path","recursive":false},{"lot_name":"lot3","path":"/foo/barr","recursive":true},{"lot_name":"lot4","path":"/1/2/3/4","recursive":true},{"lot_name":"lot4","path":"/345","recursive":true},{"lot_name":"lot5","path":"/456","recursive":false},{"lot_name":"lot5","path":"/567","recursive":true}],"usage":{"GB_being_written":{"children_contrib":3.4,"self_contrib":0.0},"dedicated_GB":{"children_contrib":8.64,"self_contrib":0.0,"total":8.64},"num_objects":{"children_contrib":10.0,"self_contrib":0.0},"objects_being_written":{"children_contrib":7.0,"self_contrib":0.0},"opportunistic_GB":{"children_contrib":0.0,"self_contrib":0.0,"total":0.0},"total_GB":{"children_contrib":8.64,"self_contrib":0.0}}})"_json; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASSERT_TRUE(output_JSON == expected_output) << output_JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [lint] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TEST_F(LotManTest, LotsFromDirTest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warning on line 626 in test/main.cpp
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
char *err_msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
char **output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const char *dir = "/1/2/3/4"; // Get a path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶