Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix messed up types in default values.yaml if no right operand is found #9

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import copy
import unittest

import yaml

from yamldifftool import filter_defaults

class TestYamlDiffTool(unittest.TestCase):
Expand Down Expand Up @@ -57,5 +60,29 @@ def test_filter_defaults_with_strict_mode(self):
filter_defaults(self.base_yaml, user_yaml, root_diff, strict=True)
self.assertEqual(root_diff, {})

def test_none_handling_in_base(self):
base_yaml = yaml.safe_load("""
global:
identity:
auth:
operate:
existingSecret:
image:
tag: 8.2.2
""")
user_yaml = yaml.safe_load("""
global:
identity:
auth:
operate:
existingSecret:
name: nameofsecret
image:
tag: 8.3.2
""")
root_diff = {}
filter_defaults(base_yaml, user_yaml, root_diff)
self.assertEqual(root_diff, {"global": {"image": {"tag": "8.3.2"}}})

if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions yamldifftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def traverse_and_set(user_provided, root_diff, path):
def filter_defaults(base, user_provided, root_diff, path=[], strict=False):
if type(user_provided) is dict:
for key in user_provided.keys():
if base is None:
continue
if type(base) is str:
continue
if not strict and key not in base.keys():
traverse_and_set(user_provided.get(key), root_diff, path + [key])
elif key in base.keys():
Expand Down