From 4bc183618ce467902e25e1db302f22b8fed96c5e Mon Sep 17 00:00:00 2001 From: iliya <68940374+12ya@users.noreply.github.com> Date: Sat, 25 Oct 2025 09:29:08 +0900 Subject: [PATCH 1/2] chore(tests): Refactor tests for idiomatic Go and minor improvements (#3561) * all: Refactor tests for idiomatic Go and minor improvements Replaced redundant 'for key, _' with 'for key' in map iterations for clarity in doctests/cmds_hash_test.go. Updated time measurement from time.Now().Sub to time.Since in hset_benchmark_test.go for idiomatic Go usage. Simplified variadic argument types from interface{} to any and removed unused min function in maintnotifications/e2e/utils_test.go. * maintnotifications/e2e/utils_test: Update variadic args type in printLog function Changed the variadic argument type in printLog from 'any' to 'interface{}' for compatibility and consistency with standard Go practices. --- doctests/cmds_hash_test.go | 4 ++-- hset_benchmark_test.go | 4 ++-- maintnotifications/e2e/utils_test.go | 7 ------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/doctests/cmds_hash_test.go b/doctests/cmds_hash_test.go index 8a4fdec4..7241bca4 100644 --- a/doctests/cmds_hash_test.go +++ b/doctests/cmds_hash_test.go @@ -79,7 +79,7 @@ func ExampleClient_hset() { keys := make([]string, 0, len(res6)) - for key, _ := range res6 { + for key := range res6 { keys = append(keys, key) } @@ -186,7 +186,7 @@ func ExampleClient_hgetall() { keys := make([]string, 0, len(hGetAllResult2)) - for key, _ := range hGetAllResult2 { + for key := range hGetAllResult2 { keys = append(keys, key) } diff --git a/hset_benchmark_test.go b/hset_benchmark_test.go index df163435..8d141f41 100644 --- a/hset_benchmark_test.go +++ b/hset_benchmark_test.go @@ -86,7 +86,7 @@ func benchmarkHSETOperations(b *testing.B, rdb *redis.Client, ctx context.Contex b.Fatalf("HSET operation failed: %v", err) } } - totalTimes = append(totalTimes, time.Now().Sub(startTime)) + totalTimes = append(totalTimes, time.Since(startTime)) } // Stop the timer to calculate metrics @@ -164,7 +164,7 @@ func benchmarkHSETPipelined(b *testing.B, rdb *redis.Client, ctx context.Context if err != nil { b.Fatalf("Pipeline execution failed: %v", err) } - totalTimes = append(totalTimes, time.Now().Sub(startTime)) + totalTimes = append(totalTimes, time.Since(startTime)) } b.StopTimer() diff --git a/maintnotifications/e2e/utils_test.go b/maintnotifications/e2e/utils_test.go index a60fac89..0aef84de 100644 --- a/maintnotifications/e2e/utils_test.go +++ b/maintnotifications/e2e/utils_test.go @@ -43,13 +43,6 @@ func containsSubstring(s, substr string) bool { return false } -func min(a, b int) int { - if a < b { - return a - } - return b -} - func printLog(group string, isError bool, format string, args ...interface{}) { _, filename, line, _ := runtime.Caller(2) filename = filepath.Base(filename) From a3a369b2f5bb7cde200af748e548bfef04481d56 Mon Sep 17 00:00:00 2001 From: iliya <68940374+12ya@users.noreply.github.com> Date: Sat, 25 Oct 2025 09:29:29 +0900 Subject: [PATCH 2/2] chore(tests): Use t.Fatal for pointer nil checks (#3562) Replaces t.Error with t.Fatal in NewRegistry and NewProcessor tests to immediately stop test execution when a nil value is encountered. --- push/push_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/push/push_test.go b/push/push_test.go index 69126f30..b98b5f16 100644 --- a/push/push_test.go +++ b/push/push_test.go @@ -144,7 +144,7 @@ func TestRegistry(t *testing.T) { t.Run("NewRegistry", func(t *testing.T) { registry := NewRegistry() if registry == nil { - t.Error("NewRegistry should not return nil") + t.Fatal("NewRegistry should not return nil") } if registry.handlers == nil { @@ -407,7 +407,7 @@ func TestProcessor(t *testing.T) { t.Run("NewProcessor", func(t *testing.T) { processor := NewProcessor() if processor == nil { - t.Error("NewProcessor should not return nil") + t.Fatal("NewProcessor should not return nil") } if processor.registry == nil {