diff options
author | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2022-11-08 09:58:26 +0300 |
---|---|---|
committer | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2022-11-08 09:58:26 +0300 |
commit | 87e29798bfe984bd6ed3e5c1ce36d45f499ffa5f (patch) | |
tree | 4b11714a165d9036e64e1b0f45866bfdd6e54c39 /tests | |
parent | ac4886b8da7d6d3b4490f187938a616bfda65b88 (diff) | |
parent | 4d9b9a2abd5c198a5dadbcdd10c413b4c4f4acd5 (diff) |
.......... [DEV-2134] updated to latest master
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libs/zbxjson/Makefile.am | 20 | ||||
-rw-r--r-- | tests/libs/zbxjson/zbx_jsonobj_query.c (renamed from tests/libs/zbxjson/zbx_jsonpath_query.c) | 46 | ||||
-rw-r--r-- | tests/libs/zbxjson/zbx_jsonobj_query.inc.yaml (renamed from tests/libs/zbxjson/zbx_jsonpath_query.inc.yaml) | 0 | ||||
-rw-r--r-- | tests/libs/zbxjson/zbx_jsonobj_query.yaml (renamed from tests/libs/zbxjson/zbx_jsonpath_query.yaml) | 182 | ||||
-rw-r--r-- | tests/libs/zbxjson/zbx_jsonpath_compile.c | 2 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/Makefile.am | 3 | ||||
-rw-r--r-- | tests/zabbix_server/poller/Makefile.am | 2 | ||||
-rw-r--r-- | tests/zabbix_server/preprocessor/zbx_item_preproc.yaml | 6 |
8 files changed, 157 insertions, 104 deletions
diff --git a/tests/libs/zbxjson/Makefile.am b/tests/libs/zbxjson/Makefile.am index d5190957c97..5f770afaf0f 100644 --- a/tests/libs/zbxjson/Makefile.am +++ b/tests/libs/zbxjson/Makefile.am @@ -3,7 +3,7 @@ noinst_PROGRAMS = \ zbx_json_decodevalue \ zbx_json_decodevalue_dyn \ zbx_jsonpath_compile \ - zbx_jsonpath_query + zbx_jsonobj_query JSON_LIBS = \ $(top_srcdir)/tests/libzbxmocktest.a \ @@ -104,22 +104,22 @@ endif zbx_jsonpath_compile_CFLAGS = -I@top_srcdir@/tests -# zbx_jsonpath_query +# zbx_jsonobj_query -zbx_jsonpath_query_SOURCES = \ - zbx_jsonpath_query.c \ +zbx_jsonobj_query_SOURCES = \ + zbx_jsonobj_query.c \ ../../zbxmocktest.h -zbx_jsonpath_query_LDADD = $(JSON_LIBS) +zbx_jsonobj_query_LDADD = $(JSON_LIBS) if SERVER -zbx_jsonpath_query_LDADD += @SERVER_LIBS@ -zbx_jsonpath_query_LDFLAGS = @SERVER_LDFLAGS@ +zbx_jsonobj_query_LDADD += @SERVER_LIBS@ +zbx_jsonobj_query_LDFLAGS = @SERVER_LDFLAGS@ else if PROXY -zbx_jsonpath_query_LDADD += @PROXY_LIBS@ -zbx_jsonpath_query_LDFLAGS = @PROXY_LDFLAGS@ +zbx_jsonobj_query_LDADD += @PROXY_LIBS@ +zbx_jsonobj_query_LDFLAGS = @PROXY_LDFLAGS@ endif endif -zbx_jsonpath_query_CFLAGS = -I@top_srcdir@/tests +zbx_jsonobj_query_CFLAGS = -I@top_srcdir@/tests diff --git a/tests/libs/zbxjson/zbx_jsonpath_query.c b/tests/libs/zbxjson/zbx_jsonobj_query.c index 6e560a6a494..25349d6932e 100644 --- a/tests/libs/zbxjson/zbx_jsonpath_query.c +++ b/tests/libs/zbxjson/zbx_jsonobj_query.c @@ -51,26 +51,13 @@ static void check_indefinite_path_result(zbx_mock_handle_t handle, const char *r zbx_mock_assert_json_eq("Indefinite query result", expected_output, returned_output); } -void zbx_mock_test_entry(void **state) +static void test_query(zbx_jsonobj_t *obj, const char *path, int expected_ret) { - const char *data, *path; - struct zbx_json_parse jp; char *output = NULL; - int expected_ret, returned_ret; + int returned_ret; zbx_mock_handle_t handle; - ZBX_UNUSED(state); - - /* reset json error to check if compilation will set it */ - zbx_set_json_strerror("%s", ""); - - data = zbx_mock_get_parameter_string("in.data"); - if (FAIL == zbx_json_open(data, &jp)) - fail_msg("Invalid json data: %s", zbx_json_strerror()); - - path = zbx_mock_get_parameter_string("in.path"); - returned_ret = zbx_jsonpath_query(&jp, path, &output); - expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return")); + returned_ret = zbx_jsonobj_query(obj, path, &output); if (FAIL == returned_ret) printf("\tzbx_jsonpath_query() failed with: %s\n", zbx_json_strerror()); @@ -97,4 +84,31 @@ void zbx_mock_test_entry(void **state) zbx_mock_assert_str_ne("tzbx_jsonpath_query() error", "", zbx_json_strerror()); zbx_free(output); + +} + +void zbx_mock_test_entry(void **state) +{ + const char *data, *path; + int expected_ret; + zbx_jsonobj_t obj; + + ZBX_UNUSED(state); + + /* reset json error to check if compilation will set it */ + zbx_set_json_strerror("%s", ""); + + data = zbx_mock_get_parameter_string("in.data"); + if (FAIL == zbx_jsonobj_open(data, &obj)) + fail_msg("Invalid json data: %s", zbx_json_strerror()); + + path = zbx_mock_get_parameter_string("in.path"); + expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return")); + + test_query(&obj, path, expected_ret); + + /* query second time to check index reuse */ + test_query(&obj, path, expected_ret); + + zbx_jsonobj_clear(&obj); } diff --git a/tests/libs/zbxjson/zbx_jsonpath_query.inc.yaml b/tests/libs/zbxjson/zbx_jsonobj_query.inc.yaml index 456f49ebe28..456f49ebe28 100644 --- a/tests/libs/zbxjson/zbx_jsonpath_query.inc.yaml +++ b/tests/libs/zbxjson/zbx_jsonobj_query.inc.yaml diff --git a/tests/libs/zbxjson/zbx_jsonpath_query.yaml b/tests/libs/zbxjson/zbx_jsonobj_query.yaml index a4b784b90d9..7e9aae0044d 100644 --- a/tests/libs/zbxjson/zbx_jsonpath_query.yaml +++ b/tests/libs/zbxjson/zbx_jsonobj_query.yaml @@ -37,7 +37,7 @@ out: return: SUCCEED --- test case: Query $.filters.price -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.filters.price @@ -46,7 +46,7 @@ out: value: 10 --- test case: Query $.filters.category -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.filters.category @@ -55,7 +55,7 @@ out: value: fiction --- test case: Query $.filters.id -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.filters.id @@ -63,7 +63,7 @@ out: return: SUCCEED --- test case: Query $.books[1].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[1].title @@ -72,7 +72,7 @@ out: value: Sword of Honour --- test case: Query $['closed message'] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $['closed message'] @@ -81,7 +81,7 @@ out: value: Store is closed --- test case: Query $.books[-1].author -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[-1].author @@ -90,7 +90,7 @@ out: value: J. R. R. Tolkien --- test case: Query $.filters -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.filters @@ -104,7 +104,7 @@ out: } --- test case: Query $.books.length() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books.length() @@ -113,7 +113,7 @@ out: value: 4 --- test case: Query $.tags[:] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.tags[:] @@ -122,7 +122,7 @@ out: value: '["a", "b", "c", "d", "e" ]' --- test case: Query $.tags[2:] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.tags[2:] @@ -131,7 +131,7 @@ out: value: '["c", "d", "e" ]' --- test case: Query $.tags[:2] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.tags[:2] @@ -140,7 +140,7 @@ out: value: '["a", "b"]' --- test case: Query $.tags[1:4] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.tags[1:4] @@ -149,7 +149,7 @@ out: value: '["b", "c", "d"]' --- test case: Query $.tags[-2:] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.tags[-2:] @@ -158,7 +158,7 @@ out: value: '["d", "e"]' --- test case: Query $.tags[:-3] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.tags[:-3] @@ -167,7 +167,7 @@ out: value: '["a", "b"]' --- test case: Query $.tags[:-3].length() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.tags[:-3].length() @@ -176,25 +176,25 @@ out: value: 2 --- test case: Query $.books[0, 2].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[0, 2].title out: return: SUCCEED - value: '["Sayings of the Century", "Moby Dick"]' + value: '["Moby Dick", "Sayings of the Century"]' --- test case: Query $.books[1]['author', "title"] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[1]['author', "title"] out: return: SUCCEED - value: '["Evelyn Waugh", "Sword of Honour"]' + value: '["Sword of Honour", "Evelyn Waugh"]' --- test case: Query $..id -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $..id @@ -203,16 +203,16 @@ out: value: '[1, 2, 3, 4]' --- test case: Query $.services..price -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.services..price out: return: SUCCEED - value: '[5, 154.99, 46, 24.5, 99.49]' + value: '[154.99, 5, 46, 24.5, 99.49]' --- test case: Query $.books[?(@.id == 1 + 1)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 1 + 1)].title @@ -221,7 +221,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == 4 / 2)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 4 / 2)].title @@ -230,7 +230,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == 7 - 5)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 7 - 5)].title @@ -239,7 +239,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == 0.4 * 5)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 0.4 * 5)].title @@ -248,7 +248,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == 4 - 0.4 * 5)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 4 - 0.4 * 5)].title @@ -257,7 +257,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == -0.4 * 5 + 4)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == -0.4 * 5 + 4)].title @@ -266,7 +266,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == 0.4 * (-5) + 4)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 0.4 * (-5) + 4)].title @@ -275,7 +275,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == 2 || @.id == 4)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 2 || @.id == 4)].title @@ -284,7 +284,7 @@ out: value: '["Sword of Honour", "The Lord of the Rings"]' --- test case: Query $.books[?(@.id == 2 && 2 * ((1 + 3) / 2 + 3) == 10)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 2 && 2 * ((1 + 3) / 2 + 3) == 10)].title @@ -293,7 +293,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.id == 2 == 1)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 2 == 1)].title @@ -302,7 +302,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(!(@.id == 2))].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(!(@.id == 2))].title @@ -311,7 +311,7 @@ out: value: '["Sayings of the Century", "Moby Dick", "The Lord of the Rings"]' --- test case: Query $.books[?(@.id != 2)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id != 2)].title @@ -320,7 +320,7 @@ out: value: '["Sayings of the Century", "Moby Dick", "The Lord of the Rings"]' --- test case: Query $.books[?(@.title =~ " of ")].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.title =~ " of ")].title @@ -329,7 +329,7 @@ out: value: '["Sayings of the Century", "Sword of Honour", "The Lord of the Rings"]' --- test case: Query $.books[?(@.price > 12.99)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.price > 12.99)].title @@ -338,7 +338,7 @@ out: value: '["The Lord of the Rings"]' --- test case: Query $.books[?(@.price >= 12.99)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.price >= 12.99)].title @@ -347,7 +347,7 @@ out: value: '["Sword of Honour", "The Lord of the Rings"]' --- test case: Query $.books[?(@.price < 12.99)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.price < 12.99)].title @@ -356,7 +356,7 @@ out: value: '["Sayings of the Century", "Moby Dick"]' --- test case: Query $.books[?(@.price <= 12.99)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.price <= 12.99)].title @@ -365,7 +365,7 @@ out: value: '["Sayings of the Century", "Sword of Honour", "Moby Dick"]' --- test case: Query $.books[?(@.author > "Herman Melville")].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.author > "Herman Melville")].title @@ -374,7 +374,7 @@ out: value: '["Sayings of the Century", "The Lord of the Rings"]' --- test case: Query $.books[?(@.author >= "Herman Melville")].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.author >= "Herman Melville")].title @@ -383,7 +383,7 @@ out: value: '["Sayings of the Century", "Moby Dick", "The Lord of the Rings"]' --- test case: Query $.books[?(@.author < "Herman Melville")].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.author < "Herman Melville")].title @@ -392,7 +392,7 @@ out: value: '["Sword of Honour"]' --- test case: Query $.books[?(@.author <= "Herman Melville")].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.author <= "Herman Melville")].title @@ -401,7 +401,7 @@ out: value: '["Sword of Honour", "Moby Dick"]' --- test case: Query $.books[?(@.price > $.filters.price)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.price > $.filters.price)].title @@ -410,7 +410,7 @@ out: value: '["Sword of Honour", "The Lord of the Rings"]' --- test case: Query $.books[?(@.category == $.filters.category)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.category == $.filters.category)].title @@ -419,7 +419,7 @@ out: value: '["Sword of Honour","Moby Dick","The Lord of the Rings"]' --- test case: Query $.books[?(@.category != $.filters.category)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.category != $.filters.category)].title @@ -428,7 +428,7 @@ out: value: '["Sayings of the Century"]' --- test case: Query $..[?(@.id)] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $..[?(@.id)] @@ -469,7 +469,7 @@ out: ] --- test case: Query $.services..[?(@.price > 50)].description -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.services..[?(@.price > 50)].description @@ -478,7 +478,7 @@ out: value: '["Printing and assembling book in A5 format", "Rebinding torn book"]' --- test case: Query $..id.length() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $..id.length() @@ -487,7 +487,7 @@ out: value: 4 --- test case: Query $.books[?(@.price >= 12.99)].length() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.price >= 12.99)].length() @@ -496,7 +496,7 @@ out: value: 2 --- test case: Query $.books[?(@.id == 2)].title.first() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.id == 2)].title.first() @@ -505,7 +505,7 @@ out: value: Sword of Honour --- test case: Query $..tags.first().length() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $..tags.first().length() @@ -514,7 +514,7 @@ out: value: 5 --- test case: Query $.bad.path.first().length() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.bad.path.first().length() @@ -522,7 +522,7 @@ out: return: FAIL --- test case: Query $.[?(@.ElementName == "test")].values.first().length() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.[?(@.ElementName == "test")].values.first().length() @@ -562,7 +562,7 @@ out: value: a --- test case: Query $.books[*].price.min() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[*].price.min() @@ -571,7 +571,7 @@ out: value: 8.95 --- test case: Query $..price.max() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $..price.max() @@ -580,7 +580,7 @@ out: value: 154.99 --- test case: Query $.books[?(@.category == "fiction")].price.avg() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.category == "fiction")].price.avg() @@ -589,7 +589,7 @@ out: value: 14.99 --- test case: Query $.books[?(@.category == $.filters.xyz)].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.category == $.filters.xyz)].title @@ -597,7 +597,7 @@ out: return: SUCCEED --- test case: Query $.filters['no filters'] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.filters['no filters'] @@ -606,16 +606,16 @@ out: value: no "filters" --- test case: Query $.services[?(@.active=="true")].servicegroup -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.services[?(@.active=="true")].servicegroup out: return: SUCCEED - value: '[1000,1001]' + value: '[1001,1000]' --- test case: Query $.services[?(@.active=="false")].servicegroup -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.services[?(@.active=="false")].servicegroup @@ -624,7 +624,7 @@ out: value: '[1002]' --- test case: Query $.books[?(@.title =~ "[a-z")].title -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.title =~ "[a-z")].title @@ -632,7 +632,7 @@ out: return: FAIL --- test case: $..books[?(!@.isbn)] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $..books[?(!@.isbn)] @@ -657,7 +657,7 @@ out: ] --- test case: $..books[?(@.isbn)] -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $..books[?(@.isbn)] @@ -684,7 +684,7 @@ out: ] --- test case: Query $.books[*].price.sum() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[*].price.sum() @@ -725,25 +725,25 @@ out: values: '[2]' --- test case: Query $.*~ -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.*~ out: return: SUCCEED - value: '["books","services","filters","closed message","tags"]' + value: '["filters", "services", "tags", "books", "closed message"]' --- test case: Query $.*~.first() -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.*~.first() out: return: SUCCEED - value: 'books' + value: 'filters' --- test case: Query $.services[?(@.servicegroup=="1002")]~ -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.services[?(@.servicegroup=="1002")]~ @@ -752,11 +752,49 @@ out: value: '["restoration"]' --- test case: Query $.books[?(@.category=="fiction")]~ -include: &include zbx_jsonpath_query.inc.yaml +include: &include zbx_jsonobj_query.inc.yaml in: data: *include path: $.books[?(@.category=="fiction")]~ out: return: SUCCEED value: '["1","2","3"]' +--- +test case: Query $.books[?(@.category=="reference")].price +include: &include zbx_jsonobj_query.inc.yaml +in: + data: *include + path: $.books[?(@.category=="reference")].price +out: + return: SUCCEED + value: '[8.95]' +--- +test case: Query $.books[1,1].title +include: &include zbx_jsonobj_query.inc.yaml +in: + data: *include + path: $.books[1,1].title +out: + return: SUCCEED + value: Sword of Honour +--- +test case: Query $.books[1:2].title +include: &include zbx_jsonobj_query.inc.yaml +in: + data: *include + path: $.books[1:2].title +out: + return: SUCCEED + value: '["Sword of Honour"]' +--- +test case: Query $.books[1]["title","title"] +include: &include zbx_jsonobj_query.inc.yaml +in: + data: *include + path: $.books[1].["title","title"] +out: + return: SUCCEED + value: Sword of Honour ... + + diff --git a/tests/libs/zbxjson/zbx_jsonpath_compile.c b/tests/libs/zbxjson/zbx_jsonpath_compile.c index e98a2c7827c..0caab92de81 100644 --- a/tests/libs/zbxjson/zbx_jsonpath_compile.c +++ b/tests/libs/zbxjson/zbx_jsonpath_compile.c @@ -54,7 +54,7 @@ static void jsonpath_token_print(char **data, size_t *data_alloc, size_t *data_o case ZBX_JSONPATH_TOKEN_PATH_RELATIVE: case ZBX_JSONPATH_TOKEN_CONST_STR: case ZBX_JSONPATH_TOKEN_CONST_NUM: - zbx_strcpy_alloc(data, data_alloc, data_offset, token->data); + zbx_strcpy_alloc(data, data_alloc, data_offset, token->text); break; case ZBX_JSONPATH_TOKEN_PAREN_LEFT: zbx_strcpy_alloc(data, data_alloc, data_offset, "("); diff --git a/tests/libs/zbxsysinfo/Makefile.am b/tests/libs/zbxsysinfo/Makefile.am index 720ce4f31ff..670be6d8d55 100644 --- a/tests/libs/zbxsysinfo/Makefile.am +++ b/tests/libs/zbxsysinfo/Makefile.am @@ -119,11 +119,11 @@ check_service_test_LDADD = \ $(top_srcdir)/src/libs/zbxthreads/libzbxthreads.a \ $(top_srcdir)/src/libs/zbxhash/libzbxhash.a \ $(top_srcdir)/src/libs/zbxnix/libzbxnix.a \ - $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ $(top_srcdir)/src/libs/zbxmutexs/libzbxmutexs.a \ $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ + $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ $(top_srcdir)/src/libs/zbxexec/libzbxexec.a \ $(top_srcdir)/src/libs/zbxvariant/libzbxvariant.a \ $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a \ @@ -238,6 +238,7 @@ check_key_access_rules_SOURCES = \ check_key_access_rules_LDADD = $(COMMON_LIB_FILES) \ $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ + $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a diff --git a/tests/zabbix_server/poller/Makefile.am b/tests/zabbix_server/poller/Makefile.am index 5531959151d..31f478fa1bb 100644 --- a/tests/zabbix_server/poller/Makefile.am +++ b/tests/zabbix_server/poller/Makefile.am @@ -10,7 +10,6 @@ POLLER_LIBS = \ $(top_srcdir)/tests/libzbxmocktest.a \ $(top_srcdir)/tests/libzbxmockdata.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ - $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ @@ -24,6 +23,7 @@ POLLER_LIBS = \ $(top_srcdir)/src/libs/zbxmutexs/libzbxmutexs.a \ $(top_srcdir)/src/libs/zbxexec/libzbxexec.a \ $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ + $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ $(top_srcdir)/src/libs/zbxhash/libzbxhash.a \ $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a \ $(top_srcdir)/src/libs/zbxvariant/libzbxvariant.a \ diff --git a/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml index ef12178fa0a..640fcbef4b7 100644 --- a/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml +++ b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml @@ -965,7 +965,7 @@ in: out: return: SUCCEED value: |- - {"b":[1, 2, 3]} + {"b":[1,2,3]} --- test case: jsonpath5 in: @@ -980,7 +980,7 @@ in: out: return: SUCCEED value: |- - [1, 2, 3] + [1,2,3] --- test case: jsonpath6 in: @@ -1008,7 +1008,7 @@ in: params: $.a['b c'] out: return: SUCCEED - value: '["one", "two", "three"]' + value: '["one","two","three"]' --- test case: jsonpath8 in: |