Skip to content

Commit

Permalink
Merge pull request #661 from k1LoW/include-vars
Browse files Browse the repository at this point in the history
Listing variable expansion patterns in the Include runner.
  • Loading branch information
k1LoW authored Oct 28, 2023
2 parents 067ca7a + 6559b9f commit 111b669
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
5 changes: 3 additions & 2 deletions operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ func TestSkipIncluded(t *testing.T) {
skipIncluded bool
want int
}{
{"testdata/book/include_*", false, 3},
{"testdata/book/include_*", true, 1},
{"testdata/book/include_*", false, 5},
{"testdata/book/include_*", true, 2},
}
for _, tt := range tests {
ops, err := Load(tt.paths, SkipIncluded(tt.skipIncluded), Runner("req", "https://api.github.com"), Runner("db", "sqlite://path/to/test.db"))
Expand Down Expand Up @@ -501,6 +501,7 @@ func TestInclude(t *testing.T) {
book string
}{
{"testdata/book/include_main.yml"},
{"testdata/book/include_vars.yml"},
}
ctx := context.Background()
for _, tt := range tests {
Expand Down
21 changes: 21 additions & 0 deletions testdata/book/include_vars_included.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
desc: Include vars (included)
if: included
steps:
-
test: |
// If it is a primitive type, the value is passed as it is.
vars.a == 12345
&& vars.b == "54321"
// If there is a variable expansion, it is reinterpreted in a form without quotes.
&& vars.c == 12345
&& vars.d == 54321
&& vars.e == 123459
&& vars.f == 543219
&& vars.g == 912345
&& vars.h == 954321
// If cast with string(), it is treated as a string.
&& vars.i == "12345"
&& vars.j == "54321"
// If the expanded value is to be passed as a string, enclose it in double quotes.
&& vars.k == "123459"
&& vars.l == "543219"
25 changes: 25 additions & 0 deletions testdata/book/include_vars_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
desc: Include vars (main)
vars:
intNumber: 12345
strNumber: "54321"
steps:
-
include:
path: include_vars_included.yml
vars:
# If it is a primitive type, the value is passed as it is.
a: 12345
b: "54321"
# If there is a variable expansion, it is reinterpreted in a form without quotes.
c: '{{ vars.intNumber }}'
d: '{{ vars.strNumber }}'
e: '{{ vars.intNumber }}9'
f: '{{ vars.strNumber }}9'
g: '9{{ vars.intNumber }}'
h: '9{{ vars.strNumber }}'
# If cast with string(), it is treated as a string.
i: '{{ string(vars.intNumber) }}'
j: '{{ string(vars.strNumber) }}'
# If the expanded value is to be passed as a string, enclose it in double quotes.
k: '"{{ vars.intNumber }}9"'
l: '"{{ vars.strNumber }}9"'

0 comments on commit 111b669

Please sign in to comment.