Fix failing tests

Signed-off-by: faizanahmad055 <faizan.ahmad55@outlook.com>
This commit is contained in:
faizanahmad055
2026-01-06 22:20:20 +01:00
parent eb38bf7470
commit e1db875efe
6 changed files with 27 additions and 12 deletions

View File

@@ -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[:])
}

View File

@@ -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))
}
}