26 Star 238 Fork 48

golang-module / 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())
})
}
}
Go
1
https://gitee.com/golang-module/dongle.git
git@gitee.com:golang-module/dongle.git
golang-module
dongle
dongle
master

搜索帮助