-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #742 from mamachanko/insert-via
Optionally, `overlay/insert` via function
- Loading branch information
Showing
8 changed files
with
306 additions
and
37 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 |
22 changes: 22 additions & 0 deletions
22
pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-via-err.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,22 @@ | ||
#@ load("@ytt:template", "template") | ||
#@ load("@ytt:overlay", "overlay") | ||
|
||
#@ def test1_left(): | ||
--- | ||
item: 1 | ||
#@ end | ||
|
||
#@ def test1_right(): | ||
#@overlay/match by=overlay.all, expects=1 | ||
#@overlay/insert before=True, via="not a function" | ||
--- | ||
#@ end | ||
|
||
--- #@ template.replace(overlay.apply(test1_left(), test1_right())) | ||
|
||
+++ | ||
|
||
ERR: | ||
- overlay.apply: Document on line stdin:12: Expected 'overlay/insert' annotation keyword argument 'via' to be function, but was starlark.String | ||
in <toplevel> | ||
stdin:15 | --- #@ template.replace(overlay.apply(test1_left(), test1_right())) |
22 changes: 22 additions & 0 deletions
22
pkg/yamltemplate/filetests/ytt-library/overlay/replace-func-err.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,22 @@ | ||
#@ load("@ytt:template", "template") | ||
#@ load("@ytt:overlay", "overlay") | ||
|
||
#@ def test1_left(): | ||
--- | ||
item: 1 | ||
#@ end | ||
|
||
#@ def test1_right(): | ||
#@overlay/match by=overlay.all, expects=1 | ||
#@overlay/replace via="not a function" | ||
--- | ||
#@ end | ||
|
||
--- #@ template.replace(overlay.apply(test1_left(), test1_right())) | ||
|
||
+++ | ||
|
||
ERR: | ||
- overlay.apply: Document on line stdin:12: Expected 'overlay/replace' annotation keyword argument 'via' to be function, but was starlark.String | ||
in <toplevel> | ||
stdin:15 | --- #@ template.replace(overlay.apply(test1_left(), test1_right())) |
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
Oops, something went wrong.