From 455ff6e9bf8daa29977c08498c873d505d1583a5 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Mon, 12 Feb 2024 09:30:58 +0100 Subject: [PATCH] use go1.22 range over ints --- ctx_test.go | 8 ++++---- deserialization_test.go | 4 ++-- examples/full-app-gourmet/views/recipe_test.go | 2 +- html_test.go | 2 +- middleware/cache/cache_test.go | 4 ++-- mux_test.go | 6 +++--- openapi_test.go | 4 ++-- params_test.go | 4 ++-- serialization_test.go | 6 +++--- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ctx_test.go b/ctx_test.go index 4961843a..22e2a61c 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -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(), @@ -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) @@ -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(), @@ -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(), diff --git a/deserialization_test.go b/deserialization_test.go index 64f9c57a..c817a198 100644 --- a/deserialization_test.go +++ b/deserialization_test.go @@ -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 { @@ -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 { diff --git a/examples/full-app-gourmet/views/recipe_test.go b/examples/full-app-gourmet/views/recipe_test.go index 5d39ca55..433832b2 100644 --- a/examples/full-app-gourmet/views/recipe_test.go +++ b/examples/full-app-gourmet/views/recipe_test.go @@ -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) diff --git a/html_test.go b/html_test.go index d4faef1f..990c5be8 100644 --- a/html_test.go +++ b/html_test.go @@ -99,7 +99,7 @@ func BenchmarkRender(b *testing.B) { expected := "
\n

Test

\n

Your name is: test

\n
\n" - for i := 0; i < b.N; i++ { + for range b.N { r := httptest.NewRequest(http.MethodGet, "/test", nil) w := httptest.NewRecorder() diff --git a/middleware/cache/cache_test.go b/middleware/cache/cache_test.go index 036a5a6f..6013ffc9 100644 --- a/middleware/cache/cache_test.go +++ b/middleware/cache/cache_test.go @@ -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() @@ -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() diff --git a/mux_test.go b/mux_test.go index a01e0572..c9d8d314 100644 --- a/mux_test.go +++ b/mux_test.go @@ -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() @@ -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() @@ -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() diff --git a/openapi_test.go b/openapi_test.go index f501b535..dcd9149a 100644 --- a/openapi_test.go +++ b/openapi_test.go @@ -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(), ) @@ -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(), ) diff --git a/params_test.go b/params_test.go index 7235641b..5a3d5bbe 100644 --- a/params_test.go +++ b/params_test.go @@ -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}") } }) diff --git a/serialization_test.go b/serialization_test.go index d14c04d8..02d50b4d 100644 --- a/serialization_test.go +++ b/serialization_test.go @@ -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) @@ -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) @@ -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)