diff options
author | Devan Goodwin <dgoodwin@redhat.com> | 2016-07-28 15:10:10 -0300 |
---|---|---|
committer | Devan Goodwin <dgoodwin@redhat.com> | 2016-08-08 15:59:09 -0300 |
commit | f28826b474df693c45ff59c64e0536bad4e1c35f (patch) | |
tree | 1df68c12e79ecfd7e1e20ad89740cdc83a8b7d3d /test/modify_yaml_tests.py | |
parent | 4bb6264a131082cc14f4a16e7b118bea2b5263de (diff) | |
download | openshift-f28826b474df693c45ff59c64e0536bad4e1c35f.tar.gz openshift-f28826b474df693c45ff59c64e0536bad4e1c35f.tar.bz2 openshift-f28826b474df693c45ff59c64e0536bad4e1c35f.tar.xz openshift-f28826b474df693c45ff59c64e0536bad4e1c35f.zip |
Fixed a bug in modify_yaml module.
When adding a property to a section that does not yet exist, the
property was being inserted into the section above where it should have
due to the pointer not being adjusted for the new section we created.
Adds a test sub-directory, would like to eventually move all the
ooinstall tests here as well so nosetests just works from top level
directory.
Diffstat (limited to 'test/modify_yaml_tests.py')
-rw-r--r-- | test/modify_yaml_tests.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/modify_yaml_tests.py b/test/modify_yaml_tests.py new file mode 100644 index 000000000..24cce4855 --- /dev/null +++ b/test/modify_yaml_tests.py @@ -0,0 +1,37 @@ +""" Tests for the modify_yaml Ansible module. """ +# pylint: disable=missing-docstring,invalid-name + +import os +import sys +import unittest + +sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../library/")] + sys.path + +# pylint: disable=import-error +from modify_yaml import set_key + +class ModifyYamlTests(unittest.TestCase): + + def test_simple_nested_value(self): + cfg = {"section": {"a": 1, "b": 2}} + changes = set_key(cfg, 'section.c', 3) + self.assertEquals(1, len(changes)) + self.assertEquals(3, cfg['section']['c']) + + # Tests a previous bug where property would land in section above where it should, + # if the destination section did not yet exist: + def test_nested_property_in_new_section(self): + cfg = { + "masterClients": { + "externalKubernetesKubeConfig": "", + "openshiftLoopbackKubeConfig": "openshift-master.kubeconfig", + }, + } + + yaml_key = 'masterClients.externalKubernetesClientConnectionOverrides.acceptContentTypes' + yaml_value = 'application/vnd.kubernetes.protobuf,application/json' + set_key(cfg, yaml_key, yaml_value) + self.assertEquals(yaml_value, cfg['masterClients'] + ['externalKubernetesClientConnectionOverrides'] + ['acceptContentTypes']) + |