salt/tests/unit/pillar/test_pepa.py
Brandon Ewing 9931a41955
Fix last key detection in pepa key_value_to_tree
pepa.key_value_to_tree only checks the name of the key when attempting
to identify the last key in a flattened key.  This can lead to strange
behavior when the final key name also occurs earlier in the flatkey.

This change explicitly checks that we are the final key in flatkey
prior to setting value.  Test included.

Also see mickep76/pepa#11 and mickep76/pepa#12
2018-12-04 20:35:34 -06:00

30 lines
745 B
Python

# -*- coding: utf-8 -*-
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
from collections import OrderedDict
# Import Salt Testing libs
from tests.support.unit import TestCase
# Import Salt Libs
import salt.pillar.pepa as pepa
class PepaPillarTestCase(TestCase):
def test_repeated_keys(self):
expected_result = {
"foo": {
"bar": {
"foo": True,
"baz": True,
},
},
}
data = OrderedDict([
('foo..bar..foo', True),
('foo..bar..baz', True),
])
result = pepa.key_value_to_tree(data)
self.assertDictEqual(result, expected_result)