1
0
mirror of https://github.com/redis/go-redis.git synced 2025-11-04 02:33:24 +03:00
Files
go-redis/maintnotifications/e2e/utils_test.go
iliya 4bc183618c 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.
2025-10-25 03:29:08 +03:00

70 lines
1.6 KiB
Go

package e2e
import (
"fmt"
"path/filepath"
"runtime"
"time"
)
func isTimeout(errMsg string) bool {
return contains(errMsg, "i/o timeout") ||
contains(errMsg, "deadline exceeded") ||
contains(errMsg, "context deadline exceeded")
}
// isTimeoutError checks if an error is a timeout error
func isTimeoutError(err error) bool {
if err == nil {
return false
}
// Check for various timeout error types
errStr := err.Error()
return isTimeout(errStr)
}
// contains checks if a string contains a substring (case-insensitive)
func contains(s, substr string) bool {
return len(s) >= len(substr) &&
(s == substr ||
(len(s) > len(substr) &&
(s[:len(substr)] == substr ||
s[len(s)-len(substr):] == substr ||
containsSubstring(s, substr))))
}
func containsSubstring(s, substr string) bool {
for i := 0; i <= len(s)-len(substr); i++ {
if s[i:i+len(substr)] == substr {
return true
}
}
return false
}
func printLog(group string, isError bool, format string, args ...interface{}) {
_, filename, line, _ := runtime.Caller(2)
filename = filepath.Base(filename)
finalFormat := "%s:%d [%s][%s] " + format + "\n"
if isError {
finalFormat = "%s:%d [%s][%s][ERROR] " + format + "\n"
}
ts := time.Now().Format("15:04:05.000")
args = append([]interface{}{filename, line, ts, group}, args...)
fmt.Printf(finalFormat, args...)
}
func actionOutputIfFailed(status *ActionStatusResponse) string {
if status.Status != StatusFailed {
return ""
}
if status.Error != nil {
return fmt.Sprintf("%v", status.Error)
}
if status.Output == nil {
return ""
}
return fmt.Sprintf("%+v", status.Output)
}