Skip to content

Commit 4bc1836

Browse files
authored
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.
1 parent f195656 commit 4bc1836

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

doctests/cmds_hash_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func ExampleClient_hset() {
7979

8080
keys := make([]string, 0, len(res6))
8181

82-
for key, _ := range res6 {
82+
for key := range res6 {
8383
keys = append(keys, key)
8484
}
8585

@@ -186,7 +186,7 @@ func ExampleClient_hgetall() {
186186

187187
keys := make([]string, 0, len(hGetAllResult2))
188188

189-
for key, _ := range hGetAllResult2 {
189+
for key := range hGetAllResult2 {
190190
keys = append(keys, key)
191191
}
192192

hset_benchmark_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func benchmarkHSETOperations(b *testing.B, rdb *redis.Client, ctx context.Contex
8686
b.Fatalf("HSET operation failed: %v", err)
8787
}
8888
}
89-
totalTimes = append(totalTimes, time.Now().Sub(startTime))
89+
totalTimes = append(totalTimes, time.Since(startTime))
9090
}
9191

9292
// Stop the timer to calculate metrics
@@ -164,7 +164,7 @@ func benchmarkHSETPipelined(b *testing.B, rdb *redis.Client, ctx context.Context
164164
if err != nil {
165165
b.Fatalf("Pipeline execution failed: %v", err)
166166
}
167-
totalTimes = append(totalTimes, time.Now().Sub(startTime))
167+
totalTimes = append(totalTimes, time.Since(startTime))
168168
}
169169

170170
b.StopTimer()

maintnotifications/e2e/utils_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ func containsSubstring(s, substr string) bool {
4343
return false
4444
}
4545

46-
func min(a, b int) int {
47-
if a < b {
48-
return a
49-
}
50-
return b
51-
}
52-
5346
func printLog(group string, isError bool, format string, args ...interface{}) {
5447
_, filename, line, _ := runtime.Caller(2)
5548
filename = filepath.Base(filename)

0 commit comments

Comments
 (0)