-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator_test.go
55 lines (45 loc) · 953 Bytes
/
generator_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
package gopass
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerate(t *testing.T) {
g := New()
t.Run("success", func(t *testing.T) {
got := g.Generate(10)
assert.Len(t, got, 10)
assert.Regexp(t, "^[0-9a-zA-Z]+$", string(got))
})
t.Run("invalid length", func(t *testing.T) {
got := g.Generate(-10)
assert.Nil(t, got)
})
}
func TestGenerateString(t *testing.T) {
g := New()
t.Run("success", func(t *testing.T) {
got := g.GenerateString(10)
assert.Len(t, got, 10)
assert.Regexp(t, "^[0-9a-zA-Z]+$", got)
})
t.Run("invalid length", func(t *testing.T) {
got := g.GenerateString(-10)
assert.Empty(t, got)
})
}
func BenchmarkGenerate(b *testing.B) {
g := New()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
g.Generate(100)
}
})
}
func BenchmarkGenerateString(b *testing.B) {
g := New()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
g.GenerateString(100)
}
})
}