Files
ris-backend-go/services/auth/password_test.go
2024-12-09 09:51:19 +07:00

35 lines
687 B
Go

package auth
import (
"testing"
)
func TestHashPassword(t *testing.T) {
hash, err := HashPassword("password")
if err != nil {
t.Errorf("error hashing password: %v", err)
}
if hash == "" {
t.Error("expected hash to be not empty")
}
if hash == "password" {
t.Error("expected hash to be different from password")
}
}
func TestComparePasswords(t *testing.T) {
hash, err := HashPassword("password")
if err != nil {
t.Errorf("error hashing password: %v", err)
}
if !ComparePasswords(hash, []byte("password")) {
t.Errorf("expected password to match hash")
}
if ComparePasswords(hash, []byte("notpassword")) {
t.Errorf("expected password to not match hash")
}
}