diff --git a/internal/e2e/error_handling_test.go b/internal/e2e/error_handling_test.go index 96ea902..7109d44 100644 --- a/internal/e2e/error_handling_test.go +++ b/internal/e2e/error_handling_test.go @@ -422,9 +422,7 @@ func TestE2E_ConcurrentPostCreation(t *testing.T) { for _, user := range users { u := user - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { client, err := ctx.loginUserSafe(t, u.Username, u.Password) if err != nil || client == nil { results <- nil @@ -443,7 +441,7 @@ func TestE2E_ConcurrentPostCreation(t *testing.T) { post, err := client.CreatePostSafe("Concurrent Post", url, "Content") results <- post - }() + }) } wg.Wait() diff --git a/internal/e2e/error_recovery_test.go b/internal/e2e/error_recovery_test.go index f8cd68f..beed19e 100644 --- a/internal/e2e/error_recovery_test.go +++ b/internal/e2e/error_recovery_test.go @@ -56,10 +56,8 @@ func TestE2E_DatabaseFailureRecovery(t *testing.T) { var wg sync.WaitGroup errors := make(chan error, 10) - for i := 0; i < 5; i++ { - wg.Add(1) - go func() { - defer wg.Done() + for range 5 { + wg.Go(func() { conn, err := sqlDB.Conn(context.Background()) if err != nil { errors <- err @@ -68,7 +66,7 @@ func TestE2E_DatabaseFailureRecovery(t *testing.T) { defer conn.Close() time.Sleep(100 * time.Millisecond) - }() + }) } wg.Wait() @@ -297,7 +295,7 @@ func TestE2E_DatabaseConnectionPool(t *testing.T) { initialStats := sqlDB.Stats() - for i := 0; i < 5; i++ { + for range 5 { req, err := http.NewRequest("GET", ctx.baseURL+"/api/posts", nil) if err != nil { continue diff --git a/internal/e2e/performance_test.go b/internal/e2e/performance_test.go index e55ede1..6a3d449 100644 --- a/internal/e2e/performance_test.go +++ b/internal/e2e/performance_test.go @@ -59,7 +59,7 @@ func TestE2E_Performance(t *testing.T) { var totalTime time.Duration iterations := 10 - for i := 0; i < iterations; i++ { + for range iterations { req, err := endpoint.req() if err != nil { t.Fatalf("Failed to create request: %v", err) @@ -98,11 +98,9 @@ func TestE2E_Performance(t *testing.T) { var errorCount int64 var wg sync.WaitGroup - for i := 0; i < concurrency; i++ { - wg.Add(1) - go func() { - defer wg.Done() - for j := 0; j < requestsPerGoroutine; j++ { + for range concurrency { + wg.Go(func() { + for range requestsPerGoroutine { req, err := http.NewRequest("GET", ctx.baseURL+"/api/posts", nil) if err != nil { atomic.AddInt64(&errorCount, 1) @@ -123,7 +121,7 @@ func TestE2E_Performance(t *testing.T) { atomic.AddInt64(&errorCount, 1) } } - }() + }) } wg.Wait() @@ -138,7 +136,7 @@ func TestE2E_Performance(t *testing.T) { createdUser := ctx.createUserWithCleanup(t, "dbperf", "StrongPass123!") authClient := ctx.loginUser(t, createdUser.Username, createdUser.Password) - for i := 0; i < 10; i++ { + for i := range 10 { authClient.CreatePost(t, fmt.Sprintf("Post %d", i), fmt.Sprintf("https://example.com/%d", i), "Content") } @@ -160,7 +158,7 @@ func TestE2E_Performance(t *testing.T) { authClient := ctx.loginUser(t, createdUser.Username, createdUser.Password) initialPosts := 50 - for i := 0; i < initialPosts; i++ { + for i := range initialPosts { authClient.CreatePost(t, fmt.Sprintf("Memory Test Post %d", i), fmt.Sprintf("https://example.com/mem%d", i), "Content") } @@ -271,16 +269,14 @@ func TestE2E_ConcurrentWrites(t *testing.T) { for _, user := range users { u := user - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { authClient, err := ctx.loginUserSafe(t, u.Username, u.Password) if err != nil { atomic.AddInt64(&errorCount, 1) return } - for i := 0; i < 5; i++ { + for i := range 5 { post, err := authClient.CreatePostSafe( fmt.Sprintf("Concurrent Post %d", i), fmt.Sprintf("https://example.com/concurrent%d-%d", u.ID, i), @@ -292,7 +288,7 @@ func TestE2E_ConcurrentWrites(t *testing.T) { atomic.AddInt64(&errorCount, 1) } } - }() + }) } wg.Wait() @@ -311,7 +307,7 @@ func TestE2E_ResponseSize(t *testing.T) { createdUser := ctx.createUserWithCleanup(t, "sizetest", "StrongPass123!") authClient := ctx.loginUser(t, createdUser.Username, createdUser.Password) - for i := 0; i < 100; i++ { + for i := range 100 { authClient.CreatePost(t, fmt.Sprintf("Post %d", i), fmt.Sprintf("https://example.com/%d", i), "Content") } diff --git a/internal/e2e/rate_limiting_test.go b/internal/e2e/rate_limiting_test.go index 619ed8e..322f807 100644 --- a/internal/e2e/rate_limiting_test.go +++ b/internal/e2e/rate_limiting_test.go @@ -38,7 +38,7 @@ func TestE2E_RateLimitingHeaders(t *testing.T) { t.Error("Expected Retry-After header when rate limited") } - var jsonResponse map[string]interface{} + var jsonResponse map[string]any body, _ := json.Marshal(map[string]string{}) _ = json.Unmarshal(body, &jsonResponse) @@ -72,7 +72,7 @@ func TestE2E_RateLimitingHeaders(t *testing.T) { if resp.StatusCode != http.StatusTooManyRequests { t.Errorf("Expected status 429 on request %d, got %d", i+1, resp.StatusCode) } else { - var errorResponse map[string]interface{} + var errorResponse map[string]any body, _ := io.ReadAll(resp.Body) if err := json.Unmarshal(body, &errorResponse); err == nil { if errorResponse["error"] == nil { diff --git a/internal/e2e/version_test.go b/internal/e2e/version_test.go index e048c67..c886ff1 100644 --- a/internal/e2e/version_test.go +++ b/internal/e2e/version_test.go @@ -30,12 +30,12 @@ func TestE2E_VersionEndpoint(t *testing.T) { return } - var apiInfo map[string]interface{} + var apiInfo map[string]any if err := json.NewDecoder(resp.Body).Decode(&apiInfo); err != nil { t.Fatalf("Failed to decode API info response: %v", err) } - data, ok := apiInfo["data"].(map[string]interface{}) + data, ok := apiInfo["data"].(map[string]any) if !ok { t.Fatalf("API info data is not a map") } @@ -74,12 +74,12 @@ func TestE2E_VersionEndpoint(t *testing.T) { return } - var healthInfo map[string]interface{} + var healthInfo map[string]any if err := json.NewDecoder(resp.Body).Decode(&healthInfo); err != nil { t.Fatalf("Failed to decode health response: %v", err) } - data, ok := healthInfo["data"].(map[string]interface{}) + data, ok := healthInfo["data"].(map[string]any) if !ok { t.Fatalf("Health data is not a map") } @@ -130,18 +130,18 @@ func TestE2E_VersionEndpoint(t *testing.T) { return } - var apiInfo map[string]interface{} + var apiInfo map[string]any if err := json.NewDecoder(apiResp.Body).Decode(&apiInfo); err != nil { t.Fatalf("Failed to decode API info: %v", err) } - var healthInfo map[string]interface{} + var healthInfo map[string]any if err := json.NewDecoder(healthResp.Body).Decode(&healthInfo); err != nil { t.Fatalf("Failed to decode health info: %v", err) } - apiData, _ := apiInfo["data"].(map[string]interface{}) - healthData, _ := healthInfo["data"].(map[string]interface{}) + apiData, _ := apiInfo["data"].(map[string]any) + healthData, _ := healthInfo["data"].(map[string]any) apiVersion, apiOk := apiData["version"].(string) healthVersion, healthOk := healthData["version"].(string) @@ -169,12 +169,12 @@ func TestE2E_VersionEndpoint(t *testing.T) { return } - var apiInfo map[string]interface{} + var apiInfo map[string]any if err := json.NewDecoder(resp.Body).Decode(&apiInfo); err != nil { t.Fatalf("Failed to decode API info: %v", err) } - data, ok := apiInfo["data"].(map[string]interface{}) + data, ok := apiInfo["data"].(map[string]any) if !ok { return } diff --git a/internal/e2e/workflows_realistic_test.go b/internal/e2e/workflows_realistic_test.go index 3bffced..8ec926c 100644 --- a/internal/e2e/workflows_realistic_test.go +++ b/internal/e2e/workflows_realistic_test.go @@ -455,7 +455,7 @@ func TestE2E_ConcurrentRequestsWithSameSession(t *testing.T) { authClient := ctx.loginUser(t, createdUser.Username, createdUser.Password) results := make(chan bool, 5) - for i := 0; i < 5; i++ { + for range 5 { go func() { profile := authClient.GetProfile(t) results <- (profile != nil && profile.Data.Username == createdUser.Username) @@ -463,7 +463,7 @@ func TestE2E_ConcurrentRequestsWithSameSession(t *testing.T) { } successCount := 0 - for i := 0; i < 5; i++ { + for range 5 { if <-results { successCount++ } @@ -562,7 +562,7 @@ func TestE2E_RapidSuccessiveActions(t *testing.T) { post := authClient.CreatePost(t, "Rapid Vote Test", "https://example.com/rapid", "Content") - for i := 0; i < 10; i++ { + for i := range 10 { voteType := "up" if i%2 == 0 { voteType = "down" diff --git a/internal/e2e/workflows_test.go b/internal/e2e/workflows_test.go index 7de40ad..6344558 100644 --- a/internal/e2e/workflows_test.go +++ b/internal/e2e/workflows_test.go @@ -134,9 +134,7 @@ func TestE2E_ConcurrentUserWorkflows(t *testing.T) { for _, user := range users { u := user - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { var err error authClient, loginErr := ctx.loginUserSafe(t, u.Username, u.Password) if loginErr != nil || authClient == nil || authClient.Token == "" { @@ -157,7 +155,7 @@ func TestE2E_ConcurrentUserWorkflows(t *testing.T) { case results <- result{userID: u.ID, err: err}: case <-done: } - }() + }) } go func() {