-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optionally overlay/insert via function
The insert overlay action has an optional 'via' kwarg, which receives the left and right node and produces the new right node, similar to the replace overlay action.
- Loading branch information
1 parent
f5ffa14
commit 486de37
Showing
5 changed files
with
238 additions
and
11 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-array-via.tpltest
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,72 @@ | ||
#@ load("@ytt:overlay", "overlay") | ||
|
||
--- | ||
#@ def test1_left(): | ||
- item: 1 | ||
- item: 2 | ||
- item: 3 | ||
#@ end | ||
|
||
#@ def is_item(indexOrKey, left, right): | ||
#@ return "item" in left | ||
#@ end | ||
|
||
#@ def insert_function(left, right): | ||
#@ return {"left": left, "right": right, "combined": {"item": left["item"] + right["item"]}} | ||
#@ end | ||
|
||
--- | ||
#@ def test1_right(): | ||
#@overlay/match by=is_item, expects=3 | ||
#@overlay/insert before=True, via=insert_function | ||
- item: 100 | ||
#@overlay/match by=is_item, expects=3 | ||
#@overlay/insert after=True, via=insert_function | ||
- item: 200 | ||
#@ end | ||
|
||
--- | ||
test1: #@ overlay.apply(test1_left(), test1_right()) | ||
|
||
+++ | ||
|
||
test1: | ||
- left: | ||
item: 1 | ||
right: | ||
item: 100 | ||
combined: | ||
item: 101 | ||
- item: 1 | ||
- left: | ||
item: 1 | ||
right: | ||
item: 200 | ||
combined: | ||
item: 201 | ||
- left: | ||
item: 2 | ||
right: | ||
item: 100 | ||
combined: | ||
item: 102 | ||
- item: 2 | ||
- left: | ||
item: 2 | ||
right: | ||
item: 200 | ||
combined: | ||
item: 202 | ||
- left: | ||
item: 3 | ||
right: | ||
item: 100 | ||
combined: | ||
item: 103 | ||
- item: 3 | ||
- left: | ||
item: 3 | ||
right: | ||
item: 200 | ||
combined: | ||
item: 203 |
82 changes: 82 additions & 0 deletions
82
pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-doc-via.tpltest
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,82 @@ | ||
#@ load("@ytt:template", "template") | ||
#@ load("@ytt:overlay", "overlay") | ||
|
||
#@ def test1_left(): | ||
--- | ||
item: 1 | ||
--- | ||
item: 2 | ||
--- | ||
item: 3 | ||
#@ end | ||
|
||
#@ def is_item(indexOrKey, left, right): | ||
#@ return "item" in left | ||
#@ end | ||
|
||
#@ def insert_function(left, right): | ||
#@ return {"left": left, "right": right, "combined": {"item": left["item"] + right["item"]}} | ||
#@ end | ||
|
||
#@ def test1_right(): | ||
#@overlay/match by=is_item, expects=3 | ||
#@overlay/insert before=True, via=insert_function | ||
--- | ||
item: 100 | ||
#@overlay/match by=is_item, expects=3 | ||
#@overlay/insert after=True, via=insert_function | ||
--- | ||
item: 200 | ||
#@ end | ||
|
||
--- #@ template.replace(overlay.apply(test1_left(), test1_right())) | ||
|
||
+++ | ||
|
||
left: | ||
item: 1 | ||
right: | ||
item: 100 | ||
combined: | ||
item: 101 | ||
--- | ||
item: 1 | ||
--- | ||
left: | ||
item: 1 | ||
right: | ||
item: 200 | ||
combined: | ||
item: 201 | ||
--- | ||
left: | ||
item: 2 | ||
right: | ||
item: 100 | ||
combined: | ||
item: 102 | ||
--- | ||
item: 2 | ||
--- | ||
left: | ||
item: 2 | ||
right: | ||
item: 200 | ||
combined: | ||
item: 202 | ||
--- | ||
left: | ||
item: 3 | ||
right: | ||
item: 100 | ||
combined: | ||
item: 103 | ||
--- | ||
item: 3 | ||
--- | ||
left: | ||
item: 3 | ||
right: | ||
item: 200 | ||
combined: | ||
item: 203 |
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