1 Star 0 Fork 51

黄苏伟/dongle

forked from dromara/dongle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
safe_url_test.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2022-12-07 09:04 . 统一单元测试格式
package dongle
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
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())
})
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/huang-suwei/dongle.git
git@gitee.com:huang-suwei/dongle.git
huang-suwei
dongle
dongle
master

搜索帮助