29 Star 289 Fork 59

GVPdromara/dongle

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
safe_url_test.go 1.37 KB
Copy Edit Raw Blame History
kuafuRace authored 8 months ago . 统一单元测试格式
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())
})
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dromara/dongle.git
git@gitee.com:dromara/dongle.git
dromara
dongle
dongle
master

Search