Skip to content

Commit 7ae2eb8

Browse files
committed
✅ add e2e
1 parent 4def4d4 commit 7ae2eb8

File tree

5 files changed

+299
-0
lines changed

5 files changed

+299
-0
lines changed

runn-e2e/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# E2E testing with runn
2+
3+
## About
4+
5+
> `runn` ( means "Run N". is pronounced /rʌ́n én/. ) is a package/tool for running operations following a scenario.
6+
7+
> Key features of runn are:
8+
> - As a tool for scenario based testing.
9+
> - As a test helper package for the Go language.
10+
> - As a tool for workflow automation.
11+
> - Support HTTP request, gRPC request, DB query, Chrome DevTools Protocol, and SSH/Local command execution
12+
> - OpenAPI Document-like syntax for HTTP request testing.
13+
> - Single binary = CI-Friendly.
14+
15+
See more: [k1LoW/runn: runn is a package/tool for running operations following a scenario.](https://github.com/k1LoW/runn)
16+
17+
## Testing
18+
19+
### Install
20+
21+
Homebrew
22+
23+
```shell
24+
brew install k1LoW/tap/runn
25+
```
26+
27+
Golang
28+
29+
```shell
30+
go install github.com/k1LoW/runn/cmd/runn@latest
31+
```
32+
33+
### Run E2E
34+
35+
```shell
36+
cd ./runn-e2e
37+
runn run runbooks/test.yml --verbose
38+
```

runn-e2e/runbooks/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
desc: "mocks tests"
2+
runners:
3+
req:
4+
endpoint: http://localhost:3000
5+
steps:
6+
hc:
7+
desc: "Health Check"
8+
req:
9+
/_hc:
10+
get:
11+
body:
12+
application/json: null
13+
test: |
14+
// Status code must be 204.
15+
current.res.status == 204
16+
post:
17+
include:
18+
path: test_post.yml
19+
comment:
20+
include:
21+
path: test_comment.yml
22+
profile:
23+
include:
24+
path: test_profile.yml

runn-e2e/runbooks/test_comment.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
desc: "comment endpoint tests"
2+
runners:
3+
req:
4+
endpoint: http://localhost:3000
5+
vars:
6+
commentId: 3
7+
if: included
8+
steps:
9+
postComment:
10+
desc: "Create new comment"
11+
req:
12+
/comments:
13+
post:
14+
body:
15+
application/json:
16+
id: "{{ vars.commentId }}"
17+
text: "new comment"
18+
post_id: "{{ vars.postId }}"
19+
test: |
20+
// Status code must be 201.
21+
current.res.status == 201
22+
&& current.res.body.id == vars.commentId
23+
&& current.res.body.text == "new comment"
24+
&& current.res.body.post_id == vars.postId
25+
getComment:
26+
desc: "Get created comment"
27+
req:
28+
/comments/{{ vars.commentId }}:
29+
get:
30+
body:
31+
application/json: null
32+
test: |
33+
// Status code must be 200.
34+
current.res.status == 200
35+
&& current.res.body.id == vars.commentId
36+
&& current.res.body.text == "new comment"
37+
&& current.res.body.post_id == vars.postId
38+
putComment:
39+
desc: "Update comment"
40+
req:
41+
/comments/{{ vars.commentId }}:
42+
put:
43+
body:
44+
application/json:
45+
id: "{{ vars.commentId }}"
46+
text: "putted comment"
47+
post_id: "{{ vars.postId }}"
48+
likes: 10
49+
test: |
50+
// Status code must be 200.
51+
current.res.status == 200
52+
&& current.res.body.id == vars.commentId
53+
&& current.res.body.text == "putted comment"
54+
&& current.res.body.post_id == vars.postId
55+
&& current.res.body.likes == 10
56+
patchComment:
57+
desc: "Change comment data"
58+
req:
59+
/comments/{{ vars.commentId }}:
60+
patch:
61+
body:
62+
application/json:
63+
text: "patched comment"
64+
likes: 20
65+
test: |
66+
// Status code must be 200.
67+
current.res.status == 200
68+
&& current.res.body.id == vars.commentId
69+
&& current.res.body.text == "patched comment"
70+
&& current.res.body.post_id == vars.postId
71+
&& current.res.body.likes == 20
72+
getAllComments:
73+
desc: "Get all comments"
74+
req:
75+
/comments:
76+
get:
77+
body:
78+
application/json: null
79+
test: |
80+
// Status code must be 200.
81+
current.res.status == 200
82+
&& len(current.res.body.comments) > 0
83+
deleteComment:
84+
desc: "Delete comment"
85+
req:
86+
/comments/{{ vars.commentId }}:
87+
delete:
88+
body:
89+
application/json: null
90+
test: |
91+
// Status code must be 200.
92+
current.res.status == 200
93+
&& current.res.body.id == vars.commentId

runn-e2e/runbooks/test_post.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
desc: "post endpoint tests"
2+
runners:
3+
req:
4+
endpoint: http://localhost:3000
5+
vars:
6+
postId: "01J85A9VQ8ZDGXDC7A00YRWKBE"
7+
if: included
8+
steps:
9+
postPost:
10+
desc: "Create new post"
11+
req:
12+
/posts:
13+
post:
14+
body:
15+
application/json:
16+
id: "{{ vars.postId }}"
17+
title: "new post"
18+
views: 0
19+
test: |
20+
// Status code must be 201.
21+
current.res.status == 201
22+
&& current.res.body.id == vars.postId
23+
&& current.res.body.title == "new post"
24+
&& current.res.body.views == 0
25+
getPost:
26+
desc: "Get created post"
27+
req:
28+
/posts/{{ vars.postId }}:
29+
get:
30+
body:
31+
application/json: null
32+
test: |
33+
// Status code must be 200.
34+
current.res.status == 200
35+
&& current.res.body.id == vars.postId
36+
&& current.res.body.title == "new post"
37+
&& current.res.body.views == 0
38+
putPost:
39+
desc: "Update post"
40+
req:
41+
/posts/{{ vars.postId }}:
42+
put:
43+
body:
44+
application/json:
45+
id: "{{ vars.postId }}"
46+
title: "putted post"
47+
views: 1000
48+
likes: 100
49+
test: |
50+
// Status code must be 200.
51+
current.res.status == 200
52+
&& current.res.body.id == vars.postId
53+
&& current.res.body.title == "putted post"
54+
&& current.res.body.views == 1000
55+
&& current.res.body.likes == 100
56+
patchPost:
57+
desc: "Change post data"
58+
req:
59+
/posts/{{ vars.postId }}:
60+
patch:
61+
body:
62+
application/json:
63+
title: "patched post"
64+
views: 2000
65+
test: |
66+
// Status code must be 200.
67+
current.res.status == 200
68+
&& current.res.body.id == vars.postId
69+
&& current.res.body.title == "patched post"
70+
&& current.res.body.views == 2000
71+
&& current.res.body.likes == 100
72+
getAllPosts:
73+
desc: "Get all posts"
74+
req:
75+
/posts:
76+
get:
77+
body:
78+
application/json: null
79+
test: |
80+
// Status code must be 200.
81+
current.res.status == 200
82+
&& len(current.res.body.posts) > 0
83+
deletePost:
84+
desc: "Delete post"
85+
req:
86+
/posts/{{ vars.postId }}:
87+
delete:
88+
body:
89+
application/json: null
90+
test: |
91+
// Status code must be 200.
92+
current.res.status == 200
93+
&& current.res.body.id == vars.postId

runn-e2e/runbooks/test_profile.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
desc: "profile endpoint tests"
2+
runners:
3+
req:
4+
endpoint: http://localhost:3000
5+
vars:
6+
profileId: "01J7BAQE1GMD78FN3J0FJCNS8T"
7+
if: included
8+
steps:
9+
putProfile:
10+
desc: "Update profile"
11+
req:
12+
/profile:
13+
put:
14+
body:
15+
application/json:
16+
id: "{{ vars.profileId }}"
17+
name: "John Smith"
18+
age: 20
19+
test: |
20+
// Status code must be 200.
21+
current.res.status == 200
22+
&& current.res.body.id == vars.profileId
23+
&& current.res.body.name == "John Smith"
24+
&& current.res.body.age == 20
25+
patchProfile:
26+
desc: "Change profile data"
27+
req:
28+
/profile:
29+
patch:
30+
body:
31+
application/json:
32+
age: 30
33+
test: |
34+
// Status code must be 200.
35+
current.res.status == 200
36+
&& current.res.body.id == vars.profileId
37+
&& current.res.body.name == "John Smith"
38+
&& current.res.body.age == 30
39+
getProfile:
40+
desc: "Get profile"
41+
req:
42+
/profile:
43+
get:
44+
body:
45+
application/json: null
46+
test: |
47+
// Status code must be 200.
48+
current.res.status == 200
49+
&& current.res.body.profile.id == vars.profileId
50+
&& current.res.body.profile.name == "John Smith"
51+
&& current.res.body.profile.age == 30

0 commit comments

Comments
 (0)