Skip to content

Commit

Permalink
use go1.22 range over ints
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Feb 12, 2024
1 parent be2016b commit 455ff6e
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func FuzzContext_Body(f *testing.F) {

func BenchmarkContext_Body(b *testing.B) {
b.Run("valid JSON body", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := range b.N {
reqBody := strings.NewReader(`{"name":"John","age":30}`)
c := NewContext[testStruct](
httptest.NewRecorder(),
Expand All @@ -322,7 +322,7 @@ func BenchmarkContext_Body(b *testing.B) {
httptest.NewRecorder(),
httptest.NewRequest("GET", "http://example.com/foo", reqBody),
readOptions{})
for i := 0; i < b.N; i++ {
for i := range b.N {
_, err := c.Body()
if err != nil {
b.Fatal(err, "iteration", i)
Expand All @@ -331,7 +331,7 @@ func BenchmarkContext_Body(b *testing.B) {
})

b.Run("invalid JSON body", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
reqBody := strings.NewReader(`{"name":"John","age":30}`)
c := NewContext[testStruct](
httptest.NewRecorder(),
Expand All @@ -345,7 +345,7 @@ func BenchmarkContext_Body(b *testing.B) {
})

b.Run("string body", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
reqBody := strings.NewReader(`{"name":"John","age":30}`)
c := NewContext[testStruct](
httptest.NewRecorder(),
Expand Down
4 changes: 2 additions & 2 deletions deserialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestReadString(t *testing.T) {
}

func BenchmarkReadJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
input := strings.NewReader(`{"A":"a","B":1,"C":true}`)
_, err := ReadJSON[BodyTest](context.Background(), input)
if err != nil {
Expand All @@ -69,7 +69,7 @@ func BenchmarkReadJSON(b *testing.B) {
}

func BenchmarkReadString(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
input := strings.NewReader(`string decoded as is`)
_, err := ReadString[string](context.Background(), input)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/full-app-gourmet/views/recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func BenchmarkShowIndexExt(b *testing.B) {

app := serverRessources.Setup()

for i := 0; i < b.N; i++ {
for range b.N {
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/", nil)

Expand Down
2 changes: 1 addition & 1 deletion html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func BenchmarkRender(b *testing.B) {

expected := "<main>\n <h1>Test</h1>\n <p>Your name is: test</p>\n</main>\n"

for i := 0; i < b.N; i++ {
for range b.N {
r := httptest.NewRequest(http.MethodGet, "/test", nil)
w := httptest.NewRecorder()

Expand Down
4 changes: 2 additions & 2 deletions middleware/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func BenchmarkCache(b *testing.B) {
fuego.Get(s, "/with-cache", baseController)

b.Run("without cache", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
r := httptest.NewRequest("GET", "/without-cache", nil)
w := httptest.NewRecorder()

Expand All @@ -223,7 +223,7 @@ func BenchmarkCache(b *testing.B) {
})

b.Run("with cache", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
r := httptest.NewRequest("GET", "/with-cache", nil)
w := httptest.NewRecorder()

Expand Down
6 changes: 3 additions & 3 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func BenchmarkRequest(b *testing.B) {
return Resp{Name: body.B}, nil
})

for i := 0; i < b.N; i++ {
for range b.N {
r := httptest.NewRequest(http.MethodPost, "/test", strings.NewReader(`{"b":"M. John","c":3}`))
w := httptest.NewRecorder()

Expand Down Expand Up @@ -341,7 +341,7 @@ func BenchmarkRequest(b *testing.B) {
}
})

for i := 0; i < b.N; i++ {
for range b.N {
r := httptest.NewRequest(http.MethodPost, "/test", strings.NewReader(`{"b":"M. John","c":3}`))
w := httptest.NewRecorder()

Expand Down Expand Up @@ -372,7 +372,7 @@ func BenchmarkRequest(b *testing.B) {
}
})

for i := 0; i < b.N; i++ {
for range b.N {
r := httptest.NewRequest(http.MethodPost, "/test", strings.NewReader(`{"b":"M. John","c":3}`))
w := httptest.NewRecorder()

Expand Down
4 changes: 2 additions & 2 deletions openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestServer_generateOpenAPI(t *testing.T) {
}

func BenchmarkRoutesRegistration(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
s := NewServer(
WithoutLogger(),
)
Expand All @@ -101,7 +101,7 @@ func BenchmarkRoutesRegistration(b *testing.B) {
}

func BenchmarkServer_generateOpenAPI(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
s := NewServer(
WithoutLogger(),
)
Expand Down
4 changes: 2 additions & 2 deletions params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ func TestParsePathParams(t *testing.T) {

func BenchmarkParsePathParams(b *testing.B) {
b.Run("empty", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
parsePathParams("/")
}
})

b.Run("several path params", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
parsePathParams("/item/{user}/{id}")
}
})
Expand Down
6 changes: 3 additions & 3 deletions serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestOutTranform(t *testing.T) {
func BenchmarkOutTransform(b *testing.B) {
b.Run("value", func(b *testing.B) {
value := tbt{Name: "John"}
for i := 0; i < b.N; i++ {
for range b.N {
value, err := transformOut(context.Background(), value)
if err != nil {
b.Fatal(err)
Expand All @@ -128,7 +128,7 @@ func BenchmarkOutTransform(b *testing.B) {

b.Run("pointer to value", func(b *testing.B) {
baseValue := tbt{Name: "Jack"}
for i := 0; i < b.N; i++ {
for i := range b.N {
// Copy baseValue to value to avoid mutating the baseValue again and again.
value := baseValue
v, err := transformOut(context.Background(), &value)
Expand All @@ -142,7 +142,7 @@ func BenchmarkOutTransform(b *testing.B) {
})

b.Run("pointer to nil", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
value, err := transformOut[*tbt](context.Background(), nil)
if err != nil {
b.Fatal(err)
Expand Down

0 comments on commit 455ff6e

Please sign in to comment.