mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Support list indexing in varReplace.
This commit is contained in:
parent
4819ce4989
commit
3cbc229990
2 changed files with 61 additions and 1 deletions
|
@ -143,6 +143,56 @@ class TestUtils(unittest.TestCase):
|
|||
|
||||
assert res == u'hello wórld'
|
||||
|
||||
def test_varReplace_list(self):
|
||||
template = 'hello ${data[1]}'
|
||||
vars = {
|
||||
'data': [ 'no-one', 'world' ]
|
||||
}
|
||||
|
||||
res = ansible.utils.varReplace(template, vars)
|
||||
|
||||
assert res == 'hello world'
|
||||
|
||||
def test_varReplace_invalid_list(self):
|
||||
template = 'hello ${data[1}'
|
||||
vars = {
|
||||
'data': [ 'no-one', 'world' ]
|
||||
}
|
||||
|
||||
res = ansible.utils.varReplace(template, vars)
|
||||
|
||||
assert res == template
|
||||
|
||||
def test_varReplace_list_oob(self):
|
||||
template = 'hello ${data[2]}'
|
||||
vars = {
|
||||
'data': [ 'no-one', 'world' ]
|
||||
}
|
||||
|
||||
res = ansible.utils.varReplace(template, vars)
|
||||
|
||||
assert res == template
|
||||
|
||||
def test_varReplace_list_nolist(self):
|
||||
template = 'hello ${data[1]}'
|
||||
vars = {
|
||||
'data': { 'no-one': 0, 'world': 1 }
|
||||
}
|
||||
|
||||
res = ansible.utils.varReplace(template, vars)
|
||||
|
||||
assert res == template
|
||||
|
||||
def test_varReplace_nested_list(self):
|
||||
template = 'hello ${data[1].msg[0]}'
|
||||
vars = {
|
||||
'data': [ 'no-one', {'msg': [ 'world'] } ]
|
||||
}
|
||||
|
||||
res = ansible.utils.varReplace(template, vars)
|
||||
|
||||
assert res == 'hello world'
|
||||
|
||||
#####################################
|
||||
### Template function tests
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue