-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-0.11] Recursive diff (#370)
* Fix strategic patch merge of env variables The key is `env`, not `envVars` * Add a Kubernetes specific recursive dict diff Understands strategic patch keys and can therefore better diff list elements * Remove unused dictdiffer dependency Co-authored-by: Will Thames <[email protected]>
- Loading branch information
1 parent
06268d8
commit 43a072d
Showing
5 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
dictdiffer | ||
jinja2 | ||
kubernetes ~= 11.0.0 | ||
python-string-utils | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,3 @@ pytest | |
pytest-bdd | ||
pytest-cov | ||
PyYAML | ||
dictdiffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from openshift.dynamic.apply import recursive_diff | ||
|
||
tests = [ | ||
dict( | ||
before = dict( | ||
kind="Service", | ||
metadata=dict(name="foo"), | ||
spec=dict(ports=[dict(port=8080, name="http")]) | ||
), | ||
after = dict( | ||
kind="Service", | ||
metadata=dict(name="foo"), | ||
spec=dict(ports=[dict(port=8080, name="http")]) | ||
), | ||
expected = None | ||
), | ||
dict( | ||
before = dict( | ||
kind="Service", | ||
metadata=dict(name="foo"), | ||
spec=dict(ports=[dict(port=8080, name="http")]) | ||
), | ||
after = dict( | ||
kind="Service", | ||
metadata=dict(name="foo"), | ||
spec=dict(ports=[dict(port=8081, name="http")]) | ||
), | ||
expected = ( | ||
dict(spec=dict(ports=[dict(port=8080, name="http")])), | ||
dict(spec=dict(ports=[dict(port=8081, name="http")])) | ||
) | ||
), | ||
dict( | ||
before = dict( | ||
kind="Service", | ||
metadata=dict(name="foo"), | ||
spec=dict(ports=[dict(port=8080, name="http"), dict(port=8081, name="https")]) | ||
), | ||
after = dict( | ||
kind="Service", | ||
metadata=dict(name="foo"), | ||
spec=dict(ports=[dict(port=8081, name="https"), dict(port=8080, name="http")]) | ||
), | ||
expected = None | ||
), | ||
|
||
dict( | ||
before = dict( | ||
kind="Pod", | ||
metadata=dict(name="foo"), | ||
spec=dict(containers=[dict(name="busybox", image="busybox", | ||
env=[dict(name="hello", value="world"), | ||
dict(name="another", value="next")])]) | ||
), | ||
after = dict( | ||
kind="Pod", | ||
metadata=dict(name="foo"), | ||
spec=dict(containers=[dict(name="busybox", image="busybox", | ||
env=[dict(name="hello", value="everyone")])]) | ||
), | ||
expected=(dict(spec=dict(containers=[dict(name="busybox", env=[dict(name="another", value="next"), dict(name="hello", value="world")])])), | ||
dict(spec=dict(containers=[dict(name="busybox", env=[dict(name="hello", value="everyone")])]))) | ||
), | ||
] | ||
|
||
|
||
def test_diff(): | ||
for test in tests: | ||
assert(recursive_diff(test['before'], test['after']) == test['expected']) |