diff options
author | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2020-03-25 12:59:31 +0300 |
---|---|---|
committer | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2020-03-25 12:59:31 +0300 |
commit | ff436e28163589da9fb59ffbd05f74a1027816c8 (patch) | |
tree | 464e779f4575b71a045ffc7488495ff588303a7b /tests/libs/zbxdbcache | |
parent | e3fd68adb9953ea9ab4b6b36764ac3f8b59306ce (diff) |
........S. [ZBXNEXT-702] create separate expand_macros function for triggers, fix tests
Diffstat (limited to 'tests/libs/zbxdbcache')
-rw-r--r-- | tests/libs/zbxdbcache/Makefile.am | 11 | ||||
-rw-r--r-- | tests/libs/zbxdbcache/zbx_dc_expand_user_macros.yaml | 73 | ||||
-rw-r--r-- | tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers.c (renamed from tests/libs/zbxdbcache/zbx_dc_expand_user_macros.c) | 3 | ||||
-rw-r--r-- | tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers.yaml | 163 |
4 files changed, 169 insertions, 81 deletions
diff --git a/tests/libs/zbxdbcache/Makefile.am b/tests/libs/zbxdbcache/Makefile.am index d5f5b028ea2..6b50fa199d9 100644 --- a/tests/libs/zbxdbcache/Makefile.am +++ b/tests/libs/zbxdbcache/Makefile.am @@ -6,8 +6,7 @@ SERVER_tests = \ dc_maintenance_match_tags \ is_item_processed_by_server \ dc_item_poller_type_update \ - zbx_dc_expand_user_macros - + zbx_dc_expand_user_macros_for_triggers endif noinst_PROGRAMS = $(SERVER_tests) @@ -140,12 +139,12 @@ dc_item_poller_type_update_LDADD = $(CACHE_LIBS) @SERVER_LIBS@ dc_item_poller_type_update_LDFLAGS = @SERVER_LDFLAGS@ dc_item_poller_type_update_CFLAGS = -I@top_srcdir@/tests -I@top_srcdir@/src/libs/zbxdbcache -zbx_dc_expand_user_macros_CFLAGS = \ +zbx_dc_expand_user_macros_for_triggers_CFLAGS = \ -I@top_srcdir@/tests \ -I@top_srcdir@/src/libs/zbxdbcache \ -Wl,--wrap=zbx_hashset_search -zbx_dc_expand_user_macros_SOURCES = zbx_dc_expand_user_macros.c -zbx_dc_expand_user_macros_LDADD = $(CACHE_LIBS) @SERVER_LIBS@ -zbx_dc_expand_user_macros_LDFLAGS = @SERVER_LDFLAGS@ +zbx_dc_expand_user_macros_for_triggers_SOURCES = zbx_dc_expand_user_macros_for_triggers.c +zbx_dc_expand_user_macros_for_triggers_LDADD = $(CACHE_LIBS) @SERVER_LIBS@ +zbx_dc_expand_user_macros_for_triggers_LDFLAGS = @SERVER_LDFLAGS@ endif diff --git a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros.yaml b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros.yaml deleted file mode 100644 index 0c2104bc889..00000000000 --- a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros.yaml +++ /dev/null @@ -1,73 +0,0 @@ ---- -test case: Expand '{1} < {$A}' with {$A}=1 -in: - macros: - - name: '{$A}' - value: 1 - expression: '{1} < {$A}' -out: - expression: '{1} < 1' ---- -test case: Expand '{1} < "{$A}"' with {$A}=1 -in: - macros: - - name: '{$A}' - value: 1 - expression: '{1} < "{$A}"' -out: - expression: '{1} < "1"' ---- -test case: Expand '{1} < {$A}' -in: - macros: [] - expression: '{1} < {$A}' -out: - expression: '{1} < {$A}' ---- -test case: Expand '{1} < {$A}' with {$A}=x -in: - macros: - - name: '{$A}' - value: x - expression: '{1} < {$A}' -out: - expression: '{1} < "x"' ---- -test case: Expand '{1} < {$A}' with {$A}="x" -in: - macros: - - name: '{$A}' - value: '"x"' - expression: '{1} < {$A}' -out: - expression: '{1} < "\"x\""' ---- -test case: Expand '{1} < "{$A}"' with {$A}="x" -in: - macros: - - name: '{$A}' - value: '"x"' - expression: '{1} < "{$A}"' -out: - expression: '{1} < "\"x\""' ---- -test case: Expand '{1} = "x" and {2} < {$A}' with {$A}="x" -in: - macros: - - name: '{$A}' - value: '"x"' - expression: '{1} = "x" and {2} < {$A}' -out: - expression: '{1} = "x" and {2} < "\"x\""' ---- -test case: Expand '{1} < "{$A}{$B}"' with {$A}=1,'{$B}'="x" -in: - macros: - - name: '{$A}' - value: 1 - - name: '{$B}' - value: '"x"' - expression: '{1} < "{$A}{$B}"' -out: - expression: '{1} < "1\"x\""' -... diff --git a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros.c b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers.c index 7a561c35803..12d787757cd 100644 --- a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros.c +++ b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers.c @@ -153,8 +153,7 @@ void zbx_mock_test_entry(void **state) /* the macro expansion relies on wrapped zbx_hashset_search which returns mocked */ /* macros when used with global macro index hashset */ - returned_expression = zbx_dc_expand_user_macros(expression, NULL, 0, zbx_macro_value_transform); - + returned_expression = zbx_dc_expand_user_macros_for_triggers(expression, NULL, 0); zbx_mock_assert_str_eq("Expanded expression", expected_expression, returned_expression); zbx_free(returned_expression); diff --git a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers.yaml b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers.yaml new file mode 100644 index 00000000000..53e2adf30de --- /dev/null +++ b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers.yaml @@ -0,0 +1,163 @@ +--- +test case: Expand '{1} < {$A}' with {$A}=1 +in: + macros: + - name: '{$A}' + value: 1 + expression: '{1} < {$A}' +out: + expression: '{1} < 1' +--- +test case: Expand '{1} < "{$A}"' with {$A}=1 +in: + macros: + - name: '{$A}' + value: 1 + expression: '{1} < "{$A}"' +out: + expression: '{1} < "1"' +--- +test case: Expand '{1} < {$A}' +in: + macros: [] + expression: '{1} < {$A}' +out: + expression: '{1} < {$A}' +--- +test case: Expand '{1} < {$A}' with {$A}=x +in: + macros: + - name: '{$A}' + value: x + expression: '{1} < {$A}' +out: + expression: '{1} < "x"' +--- +test case: Expand '{1} < {$A}' with {$A}="x" +in: + macros: + - name: '{$A}' + value: '"x"' + expression: '{1} < {$A}' +out: + expression: '{1} < "\"x\""' +--- +test case: Expand '{1} < "{$A}"' with {$A}="x" +in: + macros: + - name: '{$A}' + value: '"x"' + expression: '{1} < "{$A}"' +out: + expression: '{1} < "\"x\""' +--- +test case: Expand '{1} < "{$A}"' +in: + macros: [] + expression: '{1} < "{$A}"' +out: + expression: '{1} < "{$A}"' +--- +test case: Expand '{1} = "x" and {2} < {$A}' with {$A}="x" +in: + macros: + - name: '{$A}' + value: '"x"' + expression: '{1} = "x" and {2} < {$A}' +out: + expression: '{1} = "x" and {2} < "\"x\""' +--- +test case: Expand '{1} < "{$A}{$B}"' with {$A}=1,'{$B}'="x" +in: + macros: + - name: '{$A}' + value: 1 + - name: '{$B}' + value: '"x"' + expression: '{1} < "{$A}{$B}"' +out: + expression: '{1} < "1\"x\""' +--- +test case: Expand '{1} < "{$A}{$B}"' with {$A}=1,'{$B}'=2 +in: + macros: + - name: '{$A}' + value: 1 + - name: '{$B}' + value: 2 + expression: '{1} < "{$A}{$B}"' +out: + expression: '{1} < "12"' +--- +test case: Expand '{1} < "{$A}{$B}"' with {$A}="x",'{$B}'="y" +in: + macros: + - name: '{$A}' + value: '"x"' + - name: '{$B}' + value: '"y"' + expression: '{1} < "{$A}{$B}"' +out: + expression: '{1} < "\"x\"\"y\""' +--- +test case: Expand '{1} < {$A}{$B}' with {$A}="x",'{$B}'="y" +in: + macros: + - name: '{$A}' + value: '"x"' + - name: '{$B}' + value: '"y"' + expression: '{1} < {$A}{$B}' +out: + expression: '{1} < "\"x\"""\"y\""' +--- +test case: Expand '{1} < {$A}{$B}' with {$A}=1,'{$B}'=0 +in: + macros: + - name: '{$A}' + value: 1 + - name: '{$B}' + value: 0 + expression: '{1} < 10' +out: + expression: '{1} < 10' +--- +test case: Expand '{1} < "\"{$A}\"{$B}\""' with {$A}=\",'{$B}'=\ +in: + macros: + - name: '{$A}' + value: '\"' + - name: '{$B}' + value: '\' + expression: '{1} < "\"{$A}\"{$B}\""' +out: + expression: '{1} < "\"\\\"\"\\\""' +test case: Expand '{1} < " \" {$A} \" {$B} \" " and {$A}<>"\"{$B}" and " {$A} " = " {$A} "' with {$A}=",'{$B}'=\\ +in: + macros: + - name: '{$A}' + value: '"' + - name: '{$B}' + value: '\\' + expression: '{1} < " \" {$A} \" {$B} \" " and {$A}<>"\"{$B}" and " {$A} " = " {$A} "' +out: + expression: '{1} < " \" \" \" \\\\ \" " and "\""<>"\"\\\\" and " \" " = " \" "' +--- +test case: Expand '{1} < {$A}' with {$A}="" +in: + macros: + - name: '{$A}' + value: '' + expression: '{1} < {$A}' +out: + expression: '{1} < ""' +--- +test case: Expand '{1} < "{$A}"' with {$A}="" +in: + macros: + - name: '{$A}' + value: '' + expression: '{1} < "{$A}"' +out: + expression: '{1} < ""' +... |