-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashing_test.go
33 lines (23 loc) · 1011 Bytes
/
hashing_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
package utils
import "testing"
func TestHashPassword(t *testing.T) {
password := "something#random"
passwordHash, err := HashPassword(password)
if err != nil {
t.Errorf("Test case failed for HashPassword with argument: %s, error returned: %s", password, err.Error())
}
if passwordHash == "" {
t.Errorf("Test case failed for HashPassword with argument: %s, got: %s", password, passwordHash)
}
doesPassMatch := CheckPasswordHash(password, passwordHash)
isExpectedResult := true
if doesPassMatch != isExpectedResult {
t.Errorf("Test case failed for CheckPasswordHarsh with arguments: %s, %s, got: %t, want: %t", password, passwordHash, isExpectedResult, doesPassMatch)
}
passwordHash = "something#wrong"
doesPassMatch = CheckPasswordHash(password, passwordHash)
isExpectedResult = false
if doesPassMatch != isExpectedResult {
t.Errorf("Test case failed for CheckPasswordHarsh with arguments: %s, %s, got: %t, want: %t", password, passwordHash, isExpectedResult, doesPassMatch)
}
}