Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2021-05-07 13:28:52 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2021-05-07 13:29:10 +0300
commit76cb5ced81236880bb7e417a6c2e4626008753ad (patch)
tree6401d03a79368254ae684033337461c45c7d4b23 /tests
parentd326f183c7ea496175262369f1ff02f94f78faf8 (diff)
........S. [ZBXNEXT-6452] fixed item query filter expression validation
Diffstat (limited to 'tests')
-rw-r--r--tests/libs/zbxeval/zbx_eval_parse_expression.yaml2
-rw-r--r--tests/libs/zbxeval/zbx_eval_prepare_filter.c17
-rw-r--r--tests/libs/zbxeval/zbx_eval_prepare_filter.yaml80
-rw-r--r--tests/libs/zbxserver/evaluate_function.yaml20
4 files changed, 102 insertions, 17 deletions
diff --git a/tests/libs/zbxeval/zbx_eval_parse_expression.yaml b/tests/libs/zbxeval/zbx_eval_parse_expression.yaml
index bedecd798e8..00ff02bbbfc 100644
--- a/tests/libs/zbxeval/zbx_eval_parse_expression.yaml
+++ b/tests/libs/zbxeval/zbx_eval_parse_expression.yaml
@@ -1700,7 +1700,7 @@ in:
out:
result: FAIL
---
-test case: Succeed 'group="xyz" = tag'
+test case: Fail 'group="xyz" = tag'
in:
rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_GROUP]
expression: 'group="xyz" = tag'
diff --git a/tests/libs/zbxeval/zbx_eval_prepare_filter.c b/tests/libs/zbxeval/zbx_eval_prepare_filter.c
index e972d3d1fd8..65dbd5fd88a 100644
--- a/tests/libs/zbxeval/zbx_eval_prepare_filter.c
+++ b/tests/libs/zbxeval/zbx_eval_prepare_filter.c
@@ -31,19 +31,24 @@ void zbx_mock_test_entry(void **state)
{
zbx_eval_context_t ctx;
char *error = NULL;
+ int expected_ret, returned_ret;
ZBX_UNUSED(state);
-
- if (SUCCEED != zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"),
- ZBX_EVAL_PARSE_QUERY_EXPRESSION, &error))
+ expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.result"));
+ if (SUCCEED != (returned_ret = zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"),
+ ZBX_EVAL_PARSE_QUERY_EXPRESSION, &error)))
{
- fail_msg("failed to parse expression: %s", error);
+ printf("ERROR: %s\n", error);
}
- zbx_eval_prepare_filter(&ctx);
+ zbx_mock_assert_result_eq("return value", expected_ret, returned_ret);
- mock_compare_stack(&ctx, "out.stack");
+ if (SUCCEED == expected_ret)
+ {
+ zbx_eval_prepare_filter(&ctx);
+ mock_compare_stack(&ctx, "out.stack");
+ }
zbx_free(error);
zbx_eval_clear(&ctx);
diff --git a/tests/libs/zbxeval/zbx_eval_prepare_filter.yaml b/tests/libs/zbxeval/zbx_eval_prepare_filter.yaml
index 62f51f623b4..40ab103db35 100644
--- a/tests/libs/zbxeval/zbx_eval_prepare_filter.yaml
+++ b/tests/libs/zbxeval/zbx_eval_prepare_filter.yaml
@@ -3,6 +3,7 @@ test case: Expression 'group="x"'
in:
expression: 'group="x"'
out:
+ result: SUCCEED
stack:
- {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0}
- {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
@@ -12,6 +13,7 @@ test case: Expression 'group="x"'
in:
expression: 'group<>"x"'
out:
+ result: SUCCEED
stack:
- {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0}
- {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
@@ -21,6 +23,7 @@ test case: Expression 'group="x" and tag="a"'
in:
expression: 'group="x" and tag="a"'
out:
+ result: SUCCEED
stack:
- {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0}
- {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
@@ -34,6 +37,7 @@ test case: Expression 'group="x" or group="y" and tag="a"'
in:
expression: 'group="x" or group="y" and tag="a"'
out:
+ result: SUCCEED
stack:
- {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0}
- {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
@@ -51,6 +55,7 @@ test case: Expression 'group<>"x" or tag<>"a"'
in:
expression: 'group<>"x" or tag<>"a"'
out:
+ result: SUCCEED
stack:
- {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0}
- {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
@@ -64,6 +69,7 @@ test case: Expression '(group="Zabbix servers") or ("Zabbix servers"=group)'
in:
expression: '(group="Zabbix servers") or ("Zabbix servers"=group)'
out:
+ result: SUCCEED
stack:
- {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"Zabbix servers"', opt: 0}
- {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
@@ -72,5 +78,79 @@ out:
- {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
- {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0}
- {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0}
+---
+test case: Expression 'group=tag'
+in:
+ expression: 'group=tag'
+out:
+ result: FAIL
+---
+test case: Expression '(group)=("x")'
+in:
+ expression: '(group)=("x")'
+out:
+ result: SUCCEED
+ stack:
+ - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0}
+ - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
+ - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0}
+---
+test case: Expression '"a"="b"'
+in:
+ expression: '"a"="b"'
+out:
+ result: SUCCEED
+ stack:
+ - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"a"', opt: 0}
+ - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"b"', opt: 0}
+ - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0}
+---
+test case: Expression 'group=(tag="x")'
+in:
+ expression: 'group=(tag="x")'
+out:
+ result: FAIL
+---
+test case: Expression 'tag=("x"="y")'
+in:
+ expression: 'tag=("x"="y")'
+out:
+ result: FAIL
+---
+test case: Expression 'tag'
+in:
+ expression: 'tag'
+out:
+ result: FAIL
+---
+test case: Expression 'group={$M}'
+in:
+ expression: 'group={$M}'
+out:
+ result: SUCCEED
+ stack:
+ - {type: ZBX_EVAL_TOKEN_VAR_USERMACRO, token: '{$M}', opt: 0}
+ - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1}
+ - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0}
+---
+test case: Expression 'tag=("a" or "b")'
+in:
+ expression: 'tag=("a" or "b")'
+out:
+ result: FAIL
+---
+test case: Expression 'tag=("a" or tag = "b")'
+in:
+ expression: 'tag=("a" or tag = "b")'
+out:
+ result: FAIL
+---
+test case: Expression 'group="xyz" = tag'
+in:
+ expression: 'group="xyz" = tag'
+out:
+ result: FAIL
...
+
+
diff --git a/tests/libs/zbxserver/evaluate_function.yaml b/tests/libs/zbxserver/evaluate_function.yaml
index 13831f39713..c4f87a3cf8e 100644
--- a/tests/libs/zbxserver/evaluate_function.yaml
+++ b/tests/libs/zbxserver/evaluate_function.yaml
@@ -223,7 +223,7 @@ out:
return: SUCCEED
value: 3.5
---
-test case: Evaluate band(#1,1)
+test case: Evaluate bitand(#1,1)
in:
history:
- itemid: 1
@@ -240,13 +240,13 @@ in:
- value: 5
ts: 2017-01-10 10:05:00.000000000 +00:00
time: 2017-01-10 10:05:00.000000000 +00:00
- function: band
+ function: bitand
params: '#1,1'
out:
return: SUCCEED
value: 1
---
-test case: Evaluate band(#2,1)
+test case: Evaluate bitand(#2,1)
in:
history:
- itemid: 1
@@ -263,13 +263,13 @@ in:
- value: 5
ts: 2017-01-10 10:05:00.000000000 +00:00
time: 2017-01-10 10:05:00.000000000 +00:00
- function: band
+ function: bitand
params: '#2,1'
out:
return: SUCCEED
value: 0
---
-test case: Evaluate band(#2:now-1m,2)
+test case: Evaluate bitand(#2:now-1m,2)
in:
history:
- itemid: 1
@@ -286,7 +286,7 @@ in:
- value: 5
ts: 2017-01-10 10:05:00.000000000 +00:00
time: 2017-01-10 10:05:00.000000000 +00:00
- function: band
+ function: bitand
params: '#2:now-1m,2'
out:
return: SUCCEED
@@ -453,7 +453,7 @@ out:
return: SUCCEED
value: 1
---
-test case: Evaluate count(5m,band,1/3)
+test case: Evaluate count(5m,bitand,1/3)
in:
history:
- itemid: 1
@@ -471,12 +471,12 @@ in:
ts: 2017-01-10 10:05:00.000000000 +00:00
time: 2017-01-10 10:05:00.000000000 +00:00
function: count
- params: '5m,band,1/3'
+ params: '5m,bitand,1/3'
out:
return: SUCCEED
value: 2
---
-test case: Evaluate count(5m,band,"2/3")
+test case: Evaluate count(5m,bitand,"2/3")
in:
history:
- itemid: 1
@@ -494,7 +494,7 @@ in:
ts: 2017-01-10 10:05:00.000000000 +00:00
time: 2017-01-10 10:05:00.000000000 +00:00
function: count
- params: '5m,band,2/3'
+ params: '5m,bitand,2/3'
out:
return: SUCCEED
value: 1