mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Add dependent lookup plugin (#2164)
* Add dependent lookup plugin. * Use correct YAML booleans. * Began complete rewrite. * Only match start of error msg. * Improve tests. * Work around old Jinja2 versions. * Fix metadata. * Fix filter name.
This commit is contained in:
parent
624eb7171e
commit
eea4f45965
4 changed files with 433 additions and 0 deletions
44
tests/unit/plugins/lookup/test_dependent.py
Normal file
44
tests/unit/plugins/lookup/test_dependent.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# (c) 2020-2021, Felix Fontein <felix@fontein.de>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.unittest import TestCase
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
|
||||
MagicMock,
|
||||
)
|
||||
|
||||
from ansible.plugins.loader import lookup_loader
|
||||
|
||||
|
||||
class TestLookupModule(TestCase):
|
||||
def setUp(self):
|
||||
templar = MagicMock()
|
||||
templar._loader = None
|
||||
self.lookup = lookup_loader.get("community.general.dependent", templar=templar)
|
||||
|
||||
def test_empty(self):
|
||||
self.assertListEqual(self.lookup.run([], None), [])
|
||||
|
||||
def test_simple(self):
|
||||
self.assertListEqual(
|
||||
self.lookup.run(
|
||||
[
|
||||
{'a': '[1, 2]'},
|
||||
{'b': '[item.a + 3, item.a + 6]'},
|
||||
{'c': '[item.a + item.b * 10]'},
|
||||
],
|
||||
{},
|
||||
),
|
||||
[
|
||||
{'a': 1, 'b': 4, 'c': 41},
|
||||
{'a': 1, 'b': 7, 'c': 71},
|
||||
{'a': 2, 'b': 5, 'c': 52},
|
||||
{'a': 2, 'b': 8, 'c': 82},
|
||||
],
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue