From 79bc5273f3e386872d885a988811dd4d7bd2a242 Mon Sep 17 00:00:00 2001 From: k2tzumi Date: Sat, 28 Oct 2023 10:16:36 +0900 Subject: [PATCH 1/6] Test that a string containing numbers is not interpreted as a number when included in vars. --- operator_test.go | 1 + testdata/book/include_loop.yml | 14 ++++++++++++++ testdata/book/include_str_int.yml | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 testdata/book/include_loop.yml create mode 100644 testdata/book/include_str_int.yml diff --git a/operator_test.go b/operator_test.go index 8106f666..3c57db02 100644 --- a/operator_test.go +++ b/operator_test.go @@ -259,6 +259,7 @@ func TestRunUsingLoop(t *testing.T) { book string }{ {"testdata/book/loop.yml"}, + {"testdata/book/include_loop.yml"}, } ctx := context.Background() for _, tt := range tests { diff --git a/testdata/book/include_loop.yml b/testdata/book/include_loop.yml new file mode 100644 index 00000000..f7b990de --- /dev/null +++ b/testdata/book/include_loop.yml @@ -0,0 +1,14 @@ +desc: Test include loop +vars: + lists: + - 1 + - 2 + - 3 +steps: + include_loop: + loop: len(vars.lists) + include: + path: include_str_int.yml + vars: + a: '010000000{{ i }}' + b: '1601{{ i }}' diff --git a/testdata/book/include_str_int.yml b/testdata/book/include_str_int.yml new file mode 100644 index 00000000..054b38e6 --- /dev/null +++ b/testdata/book/include_str_int.yml @@ -0,0 +1,9 @@ +desc: For include loop test +vars: + a: null + b: null +steps: + t_main: + test: | + vars.a == "0100000001" + && vars.b == "16011" From 2e69348382c537a193d09724e8221724a5a20581 Mon Sep 17 00:00:00 2001 From: k2tzumi Date: Sat, 28 Oct 2023 10:28:02 +0900 Subject: [PATCH 2/6] include was not involved --- testdata/book/include_loop.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/testdata/book/include_loop.yml b/testdata/book/include_loop.yml index f7b990de..3453325c 100644 --- a/testdata/book/include_loop.yml +++ b/testdata/book/include_loop.yml @@ -1,14 +1,14 @@ -desc: Test include loop +desc: Test include loop(include was not involved.) vars: lists: - 1 - 2 - 3 + int: 1 steps: - include_loop: - loop: len(vars.lists) + include_not_loop: include: path: include_str_int.yml vars: - a: '010000000{{ i }}' - b: '1601{{ i }}' + a: '010000000{{ vars.int }}' + b: '1601{{ vars.int }}' From 0f155d00e9ec9a629566b05ae5b713dbccb1b8a6 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sat, 28 Oct 2023 11:08:57 +0900 Subject: [PATCH 3/6] Listing variable expansion patterns in the Include runner. --- operator_test.go | 2 +- testdata/book/include_loop.yml | 14 -------------- testdata/book/include_str_int.yml | 9 --------- testdata/book/include_vars_included.yml | 17 +++++++++++++++++ testdata/book/include_vars_main.yml | 21 +++++++++++++++++++++ 5 files changed, 39 insertions(+), 24 deletions(-) delete mode 100644 testdata/book/include_loop.yml delete mode 100644 testdata/book/include_str_int.yml create mode 100644 testdata/book/include_vars_included.yml create mode 100644 testdata/book/include_vars_main.yml diff --git a/operator_test.go b/operator_test.go index 3c57db02..de9be2a1 100644 --- a/operator_test.go +++ b/operator_test.go @@ -259,7 +259,6 @@ func TestRunUsingLoop(t *testing.T) { book string }{ {"testdata/book/loop.yml"}, - {"testdata/book/include_loop.yml"}, } ctx := context.Background() for _, tt := range tests { @@ -502,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 { diff --git a/testdata/book/include_loop.yml b/testdata/book/include_loop.yml deleted file mode 100644 index 3453325c..00000000 --- a/testdata/book/include_loop.yml +++ /dev/null @@ -1,14 +0,0 @@ -desc: Test include loop(include was not involved.) -vars: - lists: - - 1 - - 2 - - 3 - int: 1 -steps: - include_not_loop: - include: - path: include_str_int.yml - vars: - a: '010000000{{ vars.int }}' - b: '1601{{ vars.int }}' diff --git a/testdata/book/include_str_int.yml b/testdata/book/include_str_int.yml deleted file mode 100644 index 054b38e6..00000000 --- a/testdata/book/include_str_int.yml +++ /dev/null @@ -1,9 +0,0 @@ -desc: For include loop test -vars: - a: null - b: null -steps: - t_main: - test: | - vars.a == "0100000001" - && vars.b == "16011" diff --git a/testdata/book/include_vars_included.yml b/testdata/book/include_vars_included.yml new file mode 100644 index 00000000..ea60a2af --- /dev/null +++ b/testdata/book/include_vars_included.yml @@ -0,0 +1,17 @@ +desc: Include vars (included) +if: included +steps: + - + test: | + vars.a == 12345 + && vars.b == "54321" + && vars.c == 12345 + && vars.d == 54321 + && vars.e == 123459 + && vars.f == 543219 + && vars.g == 912345 + && vars.h == 954321 + && vars.i == "12345" + && vars.j == "54321" + && vars.k == "123459" + && vars.l == "543219" diff --git a/testdata/book/include_vars_main.yml b/testdata/book/include_vars_main.yml new file mode 100644 index 00000000..f47c0037 --- /dev/null +++ b/testdata/book/include_vars_main.yml @@ -0,0 +1,21 @@ +desc: Include vars +vars: + intNumber: 12345 + strNumber: "54321" +steps: + - + include: + path: include_vars_included.yml + vars: + a: 12345 + b: "54321" + c: '{{ vars.intNumber }}' + d: '{{ vars.strNumber }}' + e: '{{ vars.intNumber }}9' + f: '{{ vars.strNumber }}9' + g: '9{{ vars.intNumber }}' + h: '9{{ vars.strNumber }}' + i: '{{ string(vars.intNumber) }}' + j: '{{ string(vars.strNumber) }}' + k: '"{{ vars.intNumber }}9"' + l: '"{{ vars.strNumber }}9"' From 229dfb66002513abc4c7888684818518abbb54b5 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sat, 28 Oct 2023 11:26:01 +0900 Subject: [PATCH 4/6] Add comment --- testdata/book/include_vars_included.yml | 4 ++++ testdata/book/include_vars_main.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/testdata/book/include_vars_included.yml b/testdata/book/include_vars_included.yml index ea60a2af..ac391a50 100644 --- a/testdata/book/include_vars_included.yml +++ b/testdata/book/include_vars_included.yml @@ -3,15 +3,19 @@ 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" diff --git a/testdata/book/include_vars_main.yml b/testdata/book/include_vars_main.yml index f47c0037..f6da0cd4 100644 --- a/testdata/book/include_vars_main.yml +++ b/testdata/book/include_vars_main.yml @@ -7,15 +7,19 @@ 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"' From d4339d3cf2ed71873449bb018fe52cd5ba182236 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sat, 28 Oct 2023 11:26:57 +0900 Subject: [PATCH 5/6] Fix test --- operator_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator_test.go b/operator_test.go index de9be2a1..00ca6225 100644 --- a/operator_test.go +++ b/operator_test.go @@ -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")) From 6559b9f67f1a5a4e540101904155680f7ffc9e9b Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sat, 28 Oct 2023 12:27:49 +0900 Subject: [PATCH 6/6] bonsai --- testdata/book/include_vars_main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdata/book/include_vars_main.yml b/testdata/book/include_vars_main.yml index f6da0cd4..b14c65b5 100644 --- a/testdata/book/include_vars_main.yml +++ b/testdata/book/include_vars_main.yml @@ -1,4 +1,4 @@ -desc: Include vars +desc: Include vars (main) vars: intNumber: 12345 strNumber: "54321"