-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_test.go
38 lines (31 loc) · 836 Bytes
/
hash_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package hash
import (
"testing"
"golang.org/x/crypto/bcrypt"
)
func TestGenerateHashFromText(t *testing.T) {
text := "text"
hash, err := GenerateHashFromText(text)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
if err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(text)); err != nil {
t.Fatalf("Hash does not match text: %v", err)
}
}
func TestCompareHashAndText(t *testing.T) {
text := "text"
hash, err := GenerateHashFromText(text)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
err = CompareHashAndText(hash, text)
if err != nil {
t.Fatalf("Expected no error for matching hash and text, got %v", err)
}
wrongText := "wrong_text"
err = CompareHashAndText(hash, wrongText)
if err == nil {
t.Fatal("Expected an error for non-matching hash and text, got none")
}
}