-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrand_test.go
More file actions
68 lines (57 loc) · 1.75 KB
/
rand_test.go
File metadata and controls
68 lines (57 loc) · 1.75 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package strings
import (
"strings"
"testing"
)
func TestPasswordString(t *testing.T) {
if PasswordString(0) != "" {
t.Errorf("PasswordString(0) did not return an empty string")
}
if PasswordString(3) != "" {
t.Errorf("PasswordString(3) did not return an empty string")
}
s := PasswordString(10)
if len(s) != 10 {
t.Errorf("PasswordString(10) did not return string of length 10")
}
if !strings.ContainsAny(s, PasswordLower) {
t.Errorf("PasswordString(10) did not contain a lower case letter")
}
if !strings.ContainsAny(s, PasswordUpper) {
t.Errorf("PasswordString(10) did not contain an upper case letter")
}
if !strings.ContainsAny(s, PasswordNum) {
t.Errorf("PasswordString(10) did not contain a numeric character")
}
if !strings.ContainsAny(s, PasswordSym) {
t.Errorf("PasswordString(10) did not contain a symbol")
}
}
func TestRandomString(t *testing.T) {
if RandomString("a", 0) != "" {
t.Errorf(`RandomString("a", 0) did not return an empty string`)
}
if RandomString("a", 1) != "a" {
t.Errorf(`RandomString("a", 1) did not return "a"`)
}
if len(RandomString("abc", 1)) != 1 {
t.Errorf(`RandomString("abc", 1) did not return a string of length 1`)
}
if len(RandomString("abc", 10)) != 10 {
t.Errorf(`RandomString("abc", 10) did not return a string of length 10`)
}
}
func TestCryptoString(t *testing.T) {
if CryptoString("a", 0) != "" {
t.Errorf(`RandomString("a", 0) did not return an empty string`)
}
if CryptoString("a", 1) != "a" {
t.Errorf(`RandomString("a", 1) did not return "a"`)
}
if len(CryptoString("abc", 1)) != 1 {
t.Errorf(`RandomString("abc", 1) did not return a string of length 1`)
}
if len(CryptoString("abc", 10)) != 10 {
t.Errorf(`RandomString("abc", 10) did not return a string of length 10`)
}
}