-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_test.go
69 lines (66 loc) · 1.5 KB
/
url_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
package totp
import (
"net/url"
"testing"
)
func TestGenerator_URL(t *testing.T) {
type fields struct {
HMACHashAlgorithm string
Secret []byte
PeriodSeconds int64
Digits int
}
type args struct {
label string
issuer string
encoder Encoder
}
tests := []struct {
name string
fields fields
args args
want string
}{
{
name: "ok",
fields: fields{
HMACHashAlgorithm: "sha1",
Secret: []byte("1234567890"),
PeriodSeconds: 15,
Digits: 6,
},
args: args{
encoder: EncoderFunc(SimpleEncode),
issuer: "gopher",
label: "susi",
},
want: "otpauth://totp/susi?secret=1234567890&issuer=gopher&algorithm=SHA1&digits=6&period=15",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &Generator{
HMACHashAlgorithm: tt.fields.HMACHashAlgorithm,
Secret: tt.fields.Secret,
PeriodSeconds: tt.fields.PeriodSeconds,
Digits: tt.fields.Digits,
}
got := o.URL(tt.args.encoder, tt.args.label, tt.args.issuer)
gotURL, err := url.Parse(got)
if err != nil {
t.Error(err)
return
}
gotURL.RawQuery = gotURL.Query().Encode()
normalizeWant, err := url.Parse(tt.want)
if err != nil {
t.Error(err)
return
}
normalizeWant.RawQuery = normalizeWant.Query().Encode()
if gotURL.String() != normalizeWant.String() {
t.Errorf("Generator.URL() = %v, want %v", gotURL.String(), normalizeWant.String())
}
})
}
}