Skip to content

Commit

Permalink
[?] Add tests for GenQuery2 enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed Jun 14, 2024
1 parent 4620b32 commit 7637204
Showing 1 changed file with 62 additions and 6 deletions.
68 changes: 62 additions & 6 deletions unit_tests/src/test_rc_genquery2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
TEST_CASE("rc_genquery2")
{
SECTION("execute a simple query")
{
load_client_api_plugins();
load_client_api_plugins();

rodsEnv env;
_getRodsEnv(env);
rodsEnv env;
_getRodsEnv(env);

irods::experimental::client_connection conn;
irods::experimental::client_connection conn;

SECTION("execute a simple query")
{
auto query_string = fmt::format("select COLL_NAME where COLL_NAME = '{}'", env.rodsHome);

Genquery2Input input{};
Expand Down Expand Up @@ -56,4 +56,60 @@ TEST_CASE("rc_genquery2")
CHECK(rc_genquery2(&comm, &input, nullptr) == SYS_INVALID_INPUT_PARAM);
CHECK_FALSE(output);
}

SECTION("supports nested, multi-argument functions in projection list")
{
auto query_string = fmt::format("select concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME)) where COLL_NAME = '{}'", env.rodsHome);

Genquery2Input input{};
input.query_string = query_string.data();

char* output{};
REQUIRE(rc_genquery2(static_cast<RcComm*>(conn), &input, &output) == 0);
REQUIRE_FALSE(output == nullptr);

REQUIRE_NOTHROW([&env, &output] {
const auto result = nlohmann::json::parse(output);
CHECK_FALSE(result.empty());
const auto expected = fmt::format("{}--{}", env.rodsHome, env.rodsUserName);
CHECK(result.at(0).at(0).get_ref<const std::string&>() == expected);
}());
}

SECTION("supports nested, multi-argument functions in where clause")
{
auto query_string = fmt::format("select COLL_NAME where concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME)) = '{}--{}'", env.rodsHome, env.rodsUserName);

Genquery2Input input{};
input.query_string = query_string.data();

char* output{};
REQUIRE(rc_genquery2(static_cast<RcComm*>(conn), &input, &output) == 0);
REQUIRE_FALSE(output == nullptr);

REQUIRE_NOTHROW([&env, &output] {
const auto result = nlohmann::json::parse(output);
CHECK_FALSE(result.empty());
CHECK(result.at(0).at(0).get_ref<const std::string&>() == env.rodsHome);
}());
}

SECTION("supports nested, multi-argument functions in order-by clause")
{
auto query_string = fmt::format("select concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME)) where COLL_NAME = '{}' order by concat(COLL_NAME, concat('--', COLL_ACCESS_USER_NAME))", env.rodsHome);

Genquery2Input input{};
input.query_string = query_string.data();

char* output{};
REQUIRE(rc_genquery2(static_cast<RcComm*>(conn), &input, &output) == 0);
REQUIRE_FALSE(output == nullptr);

REQUIRE_NOTHROW([&env, &output] {
const auto result = nlohmann::json::parse(output);
CHECK_FALSE(result.empty());
const auto expected = fmt::format("{}--{}", env.rodsHome, env.rodsUserName);
CHECK(result.at(0).at(0).get_ref<const std::string&>() == expected);
}());
}
}

0 comments on commit 7637204

Please sign in to comment.