-
Notifications
You must be signed in to change notification settings - Fork 68
/
safe_url_test.go
60 lines (49 loc) · 1.37 KB
/
safe_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
package dongle
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
var safeUrlTestS = []struct {
input string
output string
}{
{"", ""},
{"www.gouguoyin.cn?sex=男&age=18", "www.gouguoyin.cn%3Fsex%3D%E7%94%B7%26age%3D18"},
}
func TestSafeURL_Encrypt_String(t *testing.T) {
for index, test := range safeUrlTestS {
e := Encode.FromString(test.input).BySafeURL()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, test.output, e.ToString())
})
}
}
func TestSafeURL_Decrypt_String(t *testing.T) {
for index, test := range safeUrlTestS {
e := Decode.FromString(test.output).BySafeURL()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, test.input, e.ToString())
})
}
}
func TestSafeURL_Encrypt_Bytes(t *testing.T) {
for index, test := range safeUrlTestS {
e := Encode.FromBytes([]byte(test.input)).BySafeURL()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.output), e.ToBytes())
})
}
}
func TestSafeURL_Decrypt_Bytes(t *testing.T) {
for index, test := range safeUrlTestS {
e := Decode.FromBytes([]byte(test.output)).BySafeURL()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.input), e.ToBytes())
})
}
}