Skip to content

Commit 84c22a9

Browse files
committed
make the REST test JSON response a bit bigger, by adding a 3rd output field
1 parent 3bed812 commit 84c22a9

File tree

12 files changed

+53
-44
lines changed

12 files changed

+53
-44
lines changed

_code/rest/buffalo/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ type (
1919
}
2020

2121
testOutput struct {
22-
ID int `json:"id"`
23-
Count int `json:"count"`
22+
ID int `json:"id"`
23+
Count int `json:"count"`
24+
FirstID string `json:"first_id"`
2425
}
2526
)
2627

@@ -37,8 +38,9 @@ func handler(ctx buffalo.Context) error {
3738
}
3839

3940
return ctx.Render(200, render.JSON(testOutput{
40-
ID: id,
41-
Count: len(in),
41+
ID: id,
42+
Count: len(in),
43+
FirstID: in[0].ID,
4244
}))
4345
}
4446

_code/rest/chi/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type (
1818
}
1919

2020
testOutput struct {
21-
ID int `json:"id"`
22-
Count int `json:"count"`
21+
ID int `json:"id"`
22+
Count int `json:"count"`
23+
FirstID string `json:"first_id"`
2324
}
2425
)
2526

@@ -45,8 +46,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
4546
w.Header().Add(contentTypeKey, contentTypeValue)
4647

4748
json.NewEncoder(w).Encode(testOutput{
48-
ID: id,
49-
Count: len(in),
49+
ID: id,
50+
Count: len(in),
51+
FirstID: in[0].ID,
5052
})
5153
}
5254

_code/rest/echo/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type (
1818
}
1919

2020
testOutput struct {
21-
ID int `json:"id"`
22-
Count int `json:"count"`
21+
ID int `json:"id"`
22+
Count int `json:"count"`
23+
FirstID string `json:"first_id"`
2324
}
2425
)
2526

@@ -36,8 +37,9 @@ func handler(ctx echo.Context) error {
3637
}
3738

3839
return ctx.JSON(200, testOutput{
39-
ID: id,
40-
Count: len(in),
40+
ID: id,
41+
Count: len(in),
42+
FirstID: in[0].ID,
4143
})
4244
}
4345

_code/rest/express/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function createWebServer() {
1616
const inputs = req.body;
1717
res.json({
1818
id: id,
19-
count: inputs.length
19+
count: inputs.length,
20+
first_id: inputs[0].id
2021
});
2122
});
2223

_code/rest/gin/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ type (
1717
}
1818

1919
testOutput struct {
20-
ID int `json:"id"`
21-
Count int `json:"count"`
20+
ID int `json:"id"`
21+
Count int `json:"count"`
22+
FirstID string `json:"first_id"`
2223
}
2324
)
2425

@@ -39,8 +40,9 @@ func handler(ctx *gin.Context) {
3940
}
4041

4142
ctx.JSON(200, testOutput{
42-
ID: id,
43-
Count: len(in),
43+
ID: id,
44+
Count: len(in),
45+
FirstID: in[0].ID,
4446
})
4547
}
4648

_code/rest/iris/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ type (
1212
}
1313

1414
testOutput struct {
15-
ID int `json:"id"`
16-
Count int `json:"count"`
15+
ID int `json:"id"`
16+
Count int `json:"count"`
17+
FirstID string `json:"first_id"`
1718
}
1819
)
1920

@@ -29,8 +30,9 @@ func handler(ctx iris.Context) {
2930
}
3031

3132
ctx.JSON(testOutput{
32-
ID: id,
33-
Count: len(in),
33+
ID: id,
34+
Count: len(in),
35+
FirstID: in[0].ID,
3436
})
3537
}
3638

_code/rest/kestrel/Startup.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public struct testOutput
2222
{
2323
public int id { get; set; }
2424
public int count { get; set; }
25+
public string first_id { get; set; }
2526
}
2627

2728
public class Startup
@@ -60,7 +61,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6061
var output = new testOutput
6162
{
6263
id = int.Parse(context.GetRouteValue("id").ToString()),
63-
count = inputs.Count
64+
count = inputs.Count,
65+
first_id = inputs[0].Id
6466
};
6567

6668
context.Response.Headers.Add("Content-Type", "application/json; charset=utf-8");

_code/rest/koa/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function createWebServer() {
1818
ctx.body = {
1919
id: id,
2020
count: inputs.length,
21+
first_id: inputs[0].id
2122
};
2223
});
2324

_code/rest/martini/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type (
1818
}
1919

2020
testOutput struct {
21-
ID int `json:"id"`
22-
Count int `json:"count"`
21+
ID int `json:"id"`
22+
Count int `json:"count"`
23+
FirstID string `json:"first_id"`
2324
}
2425
)
2526

@@ -45,8 +46,9 @@ func handler(w http.ResponseWriter, r *http.Request, params martini.Params) {
4546
w.Header().Add(contentTypeKey, contentTypeValue)
4647

4748
json.NewEncoder(w).Encode(testOutput{
48-
ID: id,
49-
Count: len(in),
49+
ID: id,
50+
Count: len(in),
51+
FirstID: in[0].ID,
5052
})
5153
}
5254

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func readTests(filename string) ([]*Test, error) {
9393
}
9494

9595
func filterTests(specificTests stringSlice, tests ...*Test) []*Test {
96+
if len(specificTests) == 0 {
97+
return tests
98+
}
99+
96100
testsAndEnvsToKeep := make(map[string][]string, len(specificTests))
97101
for _, specificTest := range specificTests {
98102
if specificTestName := strings.ToLower(specificTest); specificTestName != "" {

slice_flag.go

-11
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,3 @@ func (s *stringSlice) Set(value string) error {
1212
*s = append(*s, value)
1313
return nil
1414
}
15-
16-
// type sliceFlag[T any] struct {
17-
// slice []T
18-
// }
19-
// func (s *sliceFlag[T]) String() string {
20-
// return fmt.Sprintf("%v", s.slice)
21-
// }
22-
// func (s *sliceFlag[T]) Set(value string) error {
23-
// s.slice = append(s.slice, *(*T)(unsafe.Pointer(&value)))
24-
// return nil
25-
// }

tests.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# ::End sample YAML::
3434
- Name: Static
3535
Description: Fires {{.NumberOfRequests}} requests, receives a static message as response.
36-
NumberOfRequests: 1000000
36+
NumberOfRequests: 100000
3737
# Duration: 5s
3838
Method: GET
3939
URL: http://localhost:5000
@@ -57,7 +57,7 @@
5757
Description: >-
5858
Fires {{.NumberOfRequests}} requests with a dynamic parameter of string,
5959
receives a hello text based on the parameter as response.
60-
NumberOfRequests: 550000
60+
NumberOfRequests: 100000
6161
# Duration: 5s
6262
Method: GET
6363
URL: http://localhost:5000/hello/world
@@ -67,9 +67,9 @@
6767
- Repo: gin-gonic/gin
6868
- Repo: koajs/koa
6969
Language: Javascript
70-
- Repo: kataras/iris
70+
# - Repo: kataras/iris
7171
# - Repo: kataras/iris-private
72-
# Dir: ./_code/parameterized/iris-next
72+
Dir: ./_code/parameterized/iris-next
7373
- Repo: labstack/echo
7474
- Name: Kestrel
7575
Repo: dotnet/aspnetcore
@@ -80,9 +80,9 @@
8080
- Name: REST
8181
Description: >-
8282
Fires {{.NumberOfRequests}} requests with a dynamic parameter of int,
83-
sends JSON as request body and receives JSON as response.
84-
NumberOfRequests: 200000
85-
# Duration: 5s
83+
sends 1MB JSON as request body and receives JSON as response.
84+
NumberOfRequests: 100000
85+
# Duration: 8s
8686
Method: POST
8787
# BodyFile: ./_code/rest/request.json
8888
BodyFile: "https://microsoftedge.github.io/Demos/json-dummy-data/1MB.json"

0 commit comments

Comments
 (0)