From c6c68d91a08dc9315da8c209e2046e9a0300c997 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Thu, 6 Apr 2017 17:18:54 +0800 Subject: Add ansible action plugin `collect` - this plugin collects information or metrics from string - it is reworked from qtip.collector.parser.grep - the captured subgroups are always list even only one match found Change-Id: I1def3d7b40c7928b503fae1be531976a13e5d0be Signed-off-by: Yujun Zhang --- .../ansible_library/plugins/action/collect_test.py | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/unit/ansible_library/plugins/action/collect_test.py (limited to 'tests') diff --git a/tests/unit/ansible_library/plugins/action/collect_test.py b/tests/unit/ansible_library/plugins/action/collect_test.py new file mode 100644 index 00000000..5a9fc8f5 --- /dev/null +++ b/tests/unit/ansible_library/plugins/action/collect_test.py @@ -0,0 +1,36 @@ +############################################################################## +# Copyright (c) 2017 ZTE Corp and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import pytest + +from qtip.ansible_library.plugins.action import collect + + +@pytest.fixture +def string(): + return """Lorem ipsum dolor sit amet, +consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + +Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + +Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. +""" + + +@pytest.mark.parametrize("patterns,expected", [ + ('not exist', {}), + ('Lorem (\S+)', {}), + ('nisi ut (?P\S+)', {'name': ['aliquip']}), + ('in\s(?P\w+)', {'in': ['reprehenderit', 'voluptate', 'culpa']}) +]) +def test_collect(patterns, string, expected): + assert collect.collect(patterns, string) == expected -- cgit 1.2.3-korg