Skip to content

Commit

Permalink
make the REST test JSON response a bit bigger, by adding a 3rd output…
Browse files Browse the repository at this point in the history
… field
  • Loading branch information
kataras committed Sep 30, 2024
1 parent 3bed812 commit 84c22a9
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 44 deletions.
10 changes: 6 additions & 4 deletions _code/rest/buffalo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type (
}

testOutput struct {
ID int `json:"id"`
Count int `json:"count"`
ID int `json:"id"`
Count int `json:"count"`
FirstID string `json:"first_id"`
}
)

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

return ctx.Render(200, render.JSON(testOutput{
ID: id,
Count: len(in),
ID: id,
Count: len(in),
FirstID: in[0].ID,
}))
}

Expand Down
10 changes: 6 additions & 4 deletions _code/rest/chi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type (
}

testOutput struct {
ID int `json:"id"`
Count int `json:"count"`
ID int `json:"id"`
Count int `json:"count"`
FirstID string `json:"first_id"`
}
)

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

json.NewEncoder(w).Encode(testOutput{
ID: id,
Count: len(in),
ID: id,
Count: len(in),
FirstID: in[0].ID,
})
}

Expand Down
10 changes: 6 additions & 4 deletions _code/rest/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type (
}

testOutput struct {
ID int `json:"id"`
Count int `json:"count"`
ID int `json:"id"`
Count int `json:"count"`
FirstID string `json:"first_id"`
}
)

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

return ctx.JSON(200, testOutput{
ID: id,
Count: len(in),
ID: id,
Count: len(in),
FirstID: in[0].ID,
})
}

Expand Down
3 changes: 2 additions & 1 deletion _code/rest/express/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function createWebServer() {
const inputs = req.body;
res.json({
id: id,
count: inputs.length
count: inputs.length,
first_id: inputs[0].id
});
});

Expand Down
10 changes: 6 additions & 4 deletions _code/rest/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type (
}

testOutput struct {
ID int `json:"id"`
Count int `json:"count"`
ID int `json:"id"`
Count int `json:"count"`
FirstID string `json:"first_id"`
}
)

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

ctx.JSON(200, testOutput{
ID: id,
Count: len(in),
ID: id,
Count: len(in),
FirstID: in[0].ID,
})
}

Expand Down
10 changes: 6 additions & 4 deletions _code/rest/iris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ type (
}

testOutput struct {
ID int `json:"id"`
Count int `json:"count"`
ID int `json:"id"`
Count int `json:"count"`
FirstID string `json:"first_id"`
}
)

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

ctx.JSON(testOutput{
ID: id,
Count: len(in),
ID: id,
Count: len(in),
FirstID: in[0].ID,
})
}

Expand Down
4 changes: 3 additions & 1 deletion _code/rest/kestrel/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public struct testOutput
{
public int id { get; set; }
public int count { get; set; }
public string first_id { get; set; }
}

public class Startup
Expand Down Expand Up @@ -60,7 +61,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
var output = new testOutput
{
id = int.Parse(context.GetRouteValue("id").ToString()),
count = inputs.Count
count = inputs.Count,
first_id = inputs[0].Id
};
context.Response.Headers.Add("Content-Type", "application/json; charset=utf-8");
Expand Down
1 change: 1 addition & 0 deletions _code/rest/koa/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function createWebServer() {
ctx.body = {
id: id,
count: inputs.length,
first_id: inputs[0].id
};
});

Expand Down
10 changes: 6 additions & 4 deletions _code/rest/martini/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type (
}

testOutput struct {
ID int `json:"id"`
Count int `json:"count"`
ID int `json:"id"`
Count int `json:"count"`
FirstID string `json:"first_id"`
}
)

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

json.NewEncoder(w).Encode(testOutput{
ID: id,
Count: len(in),
ID: id,
Count: len(in),
FirstID: in[0].ID,
})
}

Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func readTests(filename string) ([]*Test, error) {
}

func filterTests(specificTests stringSlice, tests ...*Test) []*Test {
if len(specificTests) == 0 {
return tests
}

testsAndEnvsToKeep := make(map[string][]string, len(specificTests))
for _, specificTest := range specificTests {
if specificTestName := strings.ToLower(specificTest); specificTestName != "" {
Expand Down
11 changes: 0 additions & 11 deletions slice_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,3 @@ func (s *stringSlice) Set(value string) error {
*s = append(*s, value)
return nil
}

// type sliceFlag[T any] struct {
// slice []T
// }
// func (s *sliceFlag[T]) String() string {
// return fmt.Sprintf("%v", s.slice)
// }
// func (s *sliceFlag[T]) Set(value string) error {
// s.slice = append(s.slice, *(*T)(unsafe.Pointer(&value)))
// return nil
// }
14 changes: 7 additions & 7 deletions tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# ::End sample YAML::
- Name: Static
Description: Fires {{.NumberOfRequests}} requests, receives a static message as response.
NumberOfRequests: 1000000
NumberOfRequests: 100000
# Duration: 5s
Method: GET
URL: http://localhost:5000
Expand All @@ -57,7 +57,7 @@
Description: >-
Fires {{.NumberOfRequests}} requests with a dynamic parameter of string,
receives a hello text based on the parameter as response.
NumberOfRequests: 550000
NumberOfRequests: 100000
# Duration: 5s
Method: GET
URL: http://localhost:5000/hello/world
Expand All @@ -67,9 +67,9 @@
- Repo: gin-gonic/gin
- Repo: koajs/koa
Language: Javascript
- Repo: kataras/iris
# - Repo: kataras/iris
# - Repo: kataras/iris-private
# Dir: ./_code/parameterized/iris-next
Dir: ./_code/parameterized/iris-next
- Repo: labstack/echo
- Name: Kestrel
Repo: dotnet/aspnetcore
Expand All @@ -80,9 +80,9 @@
- Name: REST
Description: >-
Fires {{.NumberOfRequests}} requests with a dynamic parameter of int,
sends JSON as request body and receives JSON as response.
NumberOfRequests: 200000
# Duration: 5s
sends 1MB JSON as request body and receives JSON as response.
NumberOfRequests: 100000
# Duration: 8s
Method: POST
# BodyFile: ./_code/rest/request.json
BodyFile: "https://microsoftedge.github.io/Demos/json-dummy-data/1MB.json"
Expand Down

0 comments on commit 84c22a9

Please sign in to comment.