From 324f2de7850d5ca11794b6c5e4a19cf5b96ef0a9 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 25 Jun 2023 10:22:39 +0200 Subject: [PATCH] code review feedback: use tools/convert_to_ast.py see https://github.com/ansible/drools_jpy/pull/50#discussion_r1240917803 --- tests/asts/test_squaredaccessor_cases_ast.yml | 35 ++++++++++++++++ ...t_squaredaccessor_selectattr_cases_ast.yml | 40 +++++++++++++++++++ tests/test_ruleset.py | 2 + 3 files changed, 77 insertions(+) create mode 100644 tests/asts/test_squaredaccessor_cases_ast.yml create mode 100644 tests/asts/test_squaredaccessor_selectattr_cases_ast.yml diff --git a/tests/asts/test_squaredaccessor_cases_ast.yml b/tests/asts/test_squaredaccessor_cases_ast.yml new file mode 100644 index 0000000..1c774e1 --- /dev/null +++ b/tests/asts/test_squaredaccessor_cases_ast.yml @@ -0,0 +1,35 @@ +- RuleSet: + hosts: + - all + name: Test squared accessor + rules: + - Rule: + actions: + - Action: + action: debug + action_args: + msg: 'Testcase #1 passes' + condition: + AllCondition: + - EqualsExpression: + lhs: + Event: asd["x"][1][2].a["b"] + rhs: + Float: 3.1415 + enabled: true + name: 'r1 squared accessor' + sources: + - EventSource: + name: generic + source_args: + payload: + - asd: + x: + - 0 + - - 0 + - 0 + - a: + b: 3.1415 + id: 'Testcase #1' + source_filters: [] + source_name: generic diff --git a/tests/asts/test_squaredaccessor_selectattr_cases_ast.yml b/tests/asts/test_squaredaccessor_selectattr_cases_ast.yml new file mode 100644 index 0000000..50df567 --- /dev/null +++ b/tests/asts/test_squaredaccessor_selectattr_cases_ast.yml @@ -0,0 +1,40 @@ +- RuleSet: + hosts: + - all + name: Test squared accessor with selectattr operator + rules: + - Rule: + actions: + - Action: + action: debug + action_args: + msg: Output for testcase + condition: + AllCondition: + - SelectAttrExpression: + lhs: + Event: asd["x"][1][2].a + rhs: + key: + String: b + operator: + String: == + value: + Float: 3.1415 + enabled: true + name: r1 selectattr and squared accessor interaction + sources: + - EventSource: + name: generic + source_args: + payload: + - asd: + x: + - 0 + - - 0 + - 0 + - a: + b: 3.1415 + id: 'Testcase #1' + source_filters: [] + source_name: generic diff --git a/tests/test_ruleset.py b/tests/test_ruleset.py index b97f960..9f1829a 100644 --- a/tests/test_ruleset.py +++ b/tests/test_ruleset.py @@ -982,6 +982,8 @@ def test_assert_event_string_search(): "asts/test_select_with_same_event_ast.yml", "asts/test_self_referential_ast.yml", "asts/test_delayed_comparison_ast.yml", + "asts/test_squaredaccessor_cases_ast.yml", + "asts/test_squaredaccessor_selectattr_cases_ast.yml", ], ) def test_integrated(rulebook):