mirror of
https://github.com/stakater/Reloader.git
synced 2026-04-24 02:46:34 +00:00
Fix failing tests
Signed-off-by: faizanahmad055 <faizan.ahmad55@outlook.com>
This commit is contained in:
@@ -6,11 +6,9 @@ import (
|
||||
)
|
||||
|
||||
// GenerateSHA generates SHA from string
|
||||
// Always returns a hash value, even for empty strings, to ensure consistent behavior
|
||||
// and avoid issues with string matching operations (e.g., strings.Contains(str, "") always returns true)
|
||||
func GenerateSHA(data string) string {
|
||||
if data == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
hash := sha512.Sum512_256([]byte(data))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
|
||||
@@ -13,3 +13,16 @@ func TestGenerateSHA(t *testing.T) {
|
||||
t.Errorf("Failed to generate SHA")
|
||||
}
|
||||
}
|
||||
|
||||
// TestGenerateSHAEmptyString verifies that empty string generates a valid hash
|
||||
// This ensures consistent behavior and avoids issues with string matching operations
|
||||
func TestGenerateSHAEmptyString(t *testing.T) {
|
||||
result := GenerateSHA("")
|
||||
expected := "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a"
|
||||
if result != expected {
|
||||
t.Errorf("Failed to generate SHA for empty string. Expected: %s, Got: %s", expected, result)
|
||||
}
|
||||
if len(result) != 64 {
|
||||
t.Errorf("SHA hash should be 64 characters long, got %d", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user