-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator_test.go
98 lines (93 loc) · 1.92 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package cryptorandomstring
import (
"reflect"
"testing"
)
func TestNew(t *testing.T) {
tests := []struct {
name string
want *Generator
}{
{
name: "Generator",
want: &Generator{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := New(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %v, want %v", got, tt.want)
}
})
}
}
func TestWithCharacters(t *testing.T) {
defaultGenerator = New() // this is to garbage values set to defaultGenerator by previous tests
type args struct {
characters string
}
tests := []struct {
name string
args args
want *Generator
}{
{
name: "GeneratorWithCharacters",
args: args{characters: "abc"},
want: &Generator{characters: "abc"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := WithCharacters(tt.args.characters); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithCharacters() = %v, want %v", got, tt.want)
}
})
}
}
func TestWithKind(t *testing.T) {
type args struct {
kind string
}
tests := []struct {
name string
args args
want *Generator
}{
{
name: "GeneratorWithKind",
args: args{kind: "numeric"},
want: &Generator{kind: "numeric", characters: "abc"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := WithKind(tt.args.kind); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithKind() = %v, want %v", got, tt.want)
}
})
}
}
func TestWithLength(t *testing.T) {
type args struct {
length uint64
}
tests := []struct {
name string
args args
want *Generator
}{
{
name: "GeneratorWithLength",
args: args{length: 10},
want: &Generator{length: 10, kind: "numeric", characters: "abc"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := WithLength(tt.args.length); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithLength() = %v, want %v", got, tt.want)
}
})
}
}