diff --git a/src/json_query.c b/src/json_query.c index 39b055e4..d3e2300b 100644 --- a/src/json_query.c +++ b/src/json_query.c @@ -48,7 +48,7 @@ void log_json_error(log_level level, json_error_t *error) { } const char *ensure_valid_operator(const char *oper, baton_error_t *error) { - static size_t num_operators = 10; + static size_t num_operators = 12; static char *operators[] = { SEARCH_OP_EQUALS, SEARCH_OP_LIKE, SEARCH_OP_NOT_LIKE, SEARCH_OP_IN, SEARCH_OP_STR_GT, SEARCH_OP_STR_LT, @@ -70,7 +70,7 @@ const char *ensure_valid_operator(const char *oper, baton_error_t *error) { if (!valid) { set_baton_error(error, CAT_INVALID_ARGUMENT, "Invalid operator: expected one of " - "[%s, %s, %s, %s, %s, %s, %s, %s, %s, %s]", + "[%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s]", SEARCH_OP_EQUALS, SEARCH_OP_LIKE, SEARCH_OP_NOT_LIKE, SEARCH_OP_IN, SEARCH_OP_STR_GT, SEARCH_OP_STR_LT, diff --git a/tests/check_baton.c b/tests/check_baton.c index 93b4fcf7..8017ae7f 100644 --- a/tests/check_baton.c +++ b/tests/check_baton.c @@ -1860,6 +1860,12 @@ START_TEST(test_slurp_file) { } END_TEST +// Having metadata on an item of (a = x, a = y), a search for "a = x" +// gives correct results, as does a search for "a = y". However, +// searching for "a = x and a = y" does not (nothing is returned). +// +// This is caused by overzealous cropping of search terms introduced +// in commit d6d036 START_TEST(test_regression_github_issue83) { option_flags flags = 0; rodsEnv env; @@ -1929,6 +1935,48 @@ START_TEST(test_regression_github_issue83) { } END_TEST +// Are all the search operators accepted? "n>=", "n<=" were not being +// accepted by user input validation. +START_TEST(test_regression_github_issue137) { + option_flags flags = SEARCH_OBJECTS; + rodsEnv env; + rcComm_t *conn = rods_login(&env); + + // Not testing 'in' here + char *operators[] = { "=", "like", "not like", ">", "<", + "n>", "n<", ">=", "<=", "n>=", "n<=" }; + + for (size_t i = 0; i < 11; i++) { + json_t *avu = json_pack("{s:s, s:s, s:s}", + JSON_ATTRIBUTE_KEY, "numattr1", + JSON_VALUE_KEY, "10", + JSON_OPERATOR_KEY, operators[i]); + json_t *query = json_pack("{s:[o]}", JSON_AVUS_KEY, avu); + + baton_error_t error; + json_t *results = search_metadata(conn, query, NULL, flags, &error); + ck_assert_msg(error.code == 0, operators[i]); + + json_decref(query); + json_decref(results); + } + + // Test 'in' here + json_t *avu = json_pack("{s:s, s:[s], s:s}", + JSON_ATTRIBUTE_KEY, "numattr1", + JSON_VALUE_KEY, "10", + JSON_OPERATOR_KEY, "in"); + json_t *query = json_pack("{s:[o]}", JSON_AVUS_KEY, avu); + + baton_error_t error; + json_t *results = search_metadata(conn, query, NULL, flags, &error); + ck_assert_msg(error.code == 0, "in"); + json_decref(query); + json_decref(results); + + if (conn) rcDisconnect(conn); +} +END_TEST Suite *baton_suite(void) { Suite *suite = suite_create("baton"); @@ -2003,6 +2051,7 @@ Suite *baton_suite(void) { tcase_add_checked_fixture (regression_tests, basic_setup, basic_teardown); tcase_add_test(regression_tests, test_regression_github_issue83); + tcase_add_test(regression_tests, test_regression_github_issue137); suite_add_tcase(suite, utilities_tests); suite_add_tcase(suite, basic_tests); diff --git a/tests/metadata/meta1.imeta b/tests/metadata/meta1.imeta index c948ee6e..c546b538 100644 --- a/tests/metadata/meta1.imeta +++ b/tests/metadata/meta1.imeta @@ -23,3 +23,7 @@ add -d __IRODS_TEST_ROOT__/r1.txt a y add -d __IRODS_TEST_ROOT__/r1.txt b x add -d __IRODS_TEST_ROOT__/r1.txt b y add -d __IRODS_TEST_ROOT__/r1.txt b z + +add -d __IRODS_TEST_ROOT__/r1.txt numattr1 1 +add -d __IRODS_TEST_ROOT__/r1.txt numattr1 10 +add -d __IRODS_TEST_ROOT__/r1.txt numattr1 100