-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathrand_test.go
61 lines (51 loc) · 1.23 KB
/
rand_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package keys_test
import (
"bytes"
"strings"
"testing"
"github.com/keys-pub/keys"
"github.com/stretchr/testify/require"
)
func TestRandID(t *testing.T) {
kid := keys.RandID("test")
require.False(t, strings.Contains(kid.String(), "="))
}
func TestRandBytes(t *testing.T) {
b1 := keys.RandBytes(32)
require.Equal(t, 32, len(b1))
for i := 0; i < 1000; i++ {
b2 := keys.RandBytes(32)
require.False(t, bytes.Equal(b1, b2))
}
}
func TestRandWords(t *testing.T) {
p6 := keys.RandWords(6)
require.Equal(t, 6, len(strings.Split(p6, " ")))
require.Panics(t, func() { keys.RandWords(0) })
p1 := keys.RandWords(24)
require.Equal(t, 24, len(strings.Split(p1, " ")))
require.Panics(t, func() { keys.RandWords(25) })
for i := 0; i < 1000; i++ {
p2 := keys.RandWords(24)
require.NotEqual(t, p1, p2)
}
}
func TestRandUsername(t *testing.T) {
for i := 0; i < 100; i++ {
u := keys.RandUsername(8)
require.Equal(t, 8, len(u))
}
}
func TestRandTempPath(t *testing.T) {
p := keys.RandTempPath()
require.NotEmpty(t, p)
p2 := keys.RandTempPath()
require.NotEqual(t, p, p2)
}
func TestRandDigits(t *testing.T) {
p := keys.RandDigits(10)
require.NotEmpty(t, p)
t.Logf("%s", p)
p2 := keys.RandDigits(10)
require.NotEqual(t, p, p2)
}