-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
35 lines (30 loc) · 1011 Bytes
/
util_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
package main
import "testing"
func TestEmptyOTP(t *testing.T) {
if valid, err := oneTimePasscodeIsValid(""); err == nil {
t.Errorf("Empty OTP triggered did not trigger error as expected: %s", err)
} else if valid {
t.Errorf("Empty OTP passed validation")
}
}
func TestAlphabetOTP(t *testing.T) {
if valid, err := oneTimePasscodeIsValid("hunter2"); err == nil {
t.Errorf("Invalid (alphabetical) OTP did not trigger error as expected: %s", err)
} else if valid {
t.Errorf("Invalid (alphabetical) OTP passed validation")
}
}
func TestShortOTP(t *testing.T) {
if valid, err := oneTimePasscodeIsValid("42069"); err == nil {
t.Errorf("Invalid (short) OTP did not trigger error as expected: %s", err)
} else if valid {
t.Errorf("Invalid (short) OTP passed validation")
}
}
func TestOTP(t *testing.T) {
if valid, err := oneTimePasscodeIsValid("054389"); err != nil {
t.Errorf("A valid OTP threw an error: %s", err)
} else if !valid {
t.Errorf("A valid OTP did not pass validation")
}
}