Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop and include testing #1136

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ func TestLoad(t *testing.T) {
{"testdata/book/**/*", "nonexistent", "", "", 0},
{"testdata/book/**/*", "", "eb33c9aed04a7f1e03c1a1246b5d7bdaefd903d3", "", 1},
{"testdata/book/**/*", "", "eb33c9a", "", 1},
{"testdata/book/**/*", "", "", "http", 15},
{"testdata/book/**/*", "", "", "http", 16},
{"testdata/book/**/*", "", "", "openapi3", 9},
{"testdata/book/**/*", "", "", "http,openapi3", 15},
{"testdata/book/**/*", "", "", "http,openapi3", 16},
{"testdata/book/**/*", "", "", "http and openapi3", 9},
{"testdata/book/**/*", "", "", "http and nothing", 0},
{"testdata/book/**/*", "", "", "http or nothing", 15},
{"testdata/book/**/*", "", "", "http and not openapi3", 6},
{"testdata/book/**/*", "", "", "http or nothing", 16},
{"testdata/book/**/*", "", "", "http and not openapi3", 7},
{"testdata/book/needs_3.yml", "", "", "", 1}, // Runbooks that are only in the needs section are not counted at Load
}

Expand Down Expand Up @@ -699,8 +699,8 @@ func TestSkipIncluded(t *testing.T) {
RUNN_LABEL string
want int
}{
{"testdata/book/include_*", false, "", "", 5},
{"testdata/book/include_*", true, "", "", 2},
{"testdata/book/include_*", false, "", "", 6},
{"testdata/book/include_*", true, "", "", 3},
{"testdata/book/include_*", true, "include_a.yml", "", 1},
{"testdata/book/include_*", true, "", "label_include_a", 1},
}
Expand Down
30 changes: 30 additions & 0 deletions testdata/book/include_http.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
desc: For include http test
labels:
- http
runners:
req:
endpoint: ${HTTPBIN_END_POINT:-https://httpbin.org/}
vars:
parameter: null
if: included
steps:
get:
desc: get
req:
/get?parameter={{ vars.parameter }}:
get:
body: null
test: |
steps.get.res.status == 200
&& steps.get.res.body.args.parameter == string(vars.parameter)
post:
desc: post
req:
/post:
post:
body:
application/json:
parameter: '{{ steps.get.res.body.args.parameter }}'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow it goes to 1 on the second loop.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow it goes to 1 on the second loop.

I can't confirm the result you're talking about.
Can you still confirm it there?

$ go run cmd/runn/main.go run testdata/book/loop_and_include.yml --debug
Run "loop" on "For loop & include test".steps.loop
Run "get" on "For include http test".steps.get
-----START HTTP REQUEST-----
GET /get?parameter=1 HTTP/1.1
Host: httpbin.org


-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 309
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:51 GMT
Server: gunicorn/19.9.0

{
  "args": {
    "parameter": "1"
  },
  "headers": {
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-6772428f-6cbfe5e14bd6bda63205ce38"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/get?parameter=1"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.get

Run "post" on "For include http test".steps.post
-----START HTTP REQUEST-----
POST /post HTTP/1.1
Host: httpbin.org
Content-Type: application/json

{"parameter":"1"}
-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 450
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:51 GMT
Server: gunicorn/19.9.0

{
  "args": {},
  "data": "{\"parameter\":\"1\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "gzip",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-6772428f-5b71bfed3b1e0f452d870a0a"
  },
  "json": {
    "parameter": "1"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/post"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.post
Run "get" on "For include http test".steps.get
-----START HTTP REQUEST-----
GET /get?parameter=2 HTTP/1.1
Host: httpbin.org


-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 309
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:52 GMT
Server: gunicorn/19.9.0

{
  "args": {
    "parameter": "2"
  },
  "headers": {
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-67724290-7fd87e3d213dafa56f35b719"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/get?parameter=2"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.get

Run "post" on "For include http test".steps.post
-----START HTTP REQUEST-----
POST /post HTTP/1.1
Host: httpbin.org
Content-Type: application/json

{"parameter":"2"}
-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 450
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:52 GMT
Server: gunicorn/19.9.0

{
  "args": {},
  "data": "{\"parameter\":\"2\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "gzip",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-67724290-1e05eaa82f42f63b7f56e282"
  },
  "json": {
    "parameter": "2"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/post"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.post
Run "get" on "For include http test".steps.get
-----START HTTP REQUEST-----
GET /get?parameter=3 HTTP/1.1
Host: httpbin.org


-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 309
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:54 GMT
Server: gunicorn/19.9.0

{
  "args": {
    "parameter": "3"
  },
  "headers": {
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-67724291-01bdb6224e726a5d541b4266"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/get?parameter=3"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.get

Run "post" on "For include http test".steps.post
-----START HTTP REQUEST-----
POST /post HTTP/1.1
Host: httpbin.org
Content-Type: application/json

{"parameter":"3"}
-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 450
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:54 GMT
Server: gunicorn/19.9.0

{
  "args": {},
  "data": "{\"parameter\":\"3\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "gzip",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-67724292-1eb8db232fb3637c3b063aa3"
  },
  "json": {
    "parameter": "3"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/post"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.post
Run "get" on "For include http test".steps.get
-----START HTTP REQUEST-----
GET /get?parameter=4 HTTP/1.1
Host: httpbin.org


-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 309
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:55 GMT
Server: gunicorn/19.9.0

{
  "args": {
    "parameter": "4"
  },
  "headers": {
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-67724293-0807057c7538327a517df383"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/get?parameter=4"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.get

Run "post" on "For include http test".steps.post
-----START HTTP REQUEST-----
POST /post HTTP/1.1
Host: httpbin.org
Content-Type: application/json

{"parameter":"4"}
-----END HTTP REQUEST-----
-----START HTTP RESPONSE-----
HTTP/2.0 200 OK
Content-Length: 450
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 30 Dec 2024 06:49:55 GMT
Server: gunicorn/19.9.0

{
  "args": {},
  "data": "{\"parameter\":\"4\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "gzip",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-67724293-7a7dc6ba5763e5ad18775a02"
  },
  "json": {
    "parameter": "4"
  },
  "origin": "123.198.33.120",
  "url": "https://httpbin.org/post"
}

-----END HTTP RESPONSE-----
Run "test" on "For include http test".steps.post
.

1 scenario, 0 skipped, 0 failures
$

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The events are only confirmed on CI in the scenario tests that we implement in our work.
Currently, the scenario is not reproduced locally, but the sample implemented scenario is valid? is also unknown.

test: |
steps.post.res.status == 200
&& fromJSON(steps.post.res.body.data).parameter == steps.get.res.body.args.parameter
16 changes: 16 additions & 0 deletions testdata/book/loop_and_include.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
desc: For loop & include test
vars:
patterns:
- 1
- 2
- 3
- 4
steps:
loop:
desc: loop
loop:
count: len(vars.patterns)
include:
path: ./include_http.yml
vars:
parameter: '{{ vars.patterns[i] }}'
Loading