1 Star 0 Fork 63

jangocheng/dongle

forked from dromara/dongle 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
base64_url_test.go 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
kuafuRace 提交于 2022-11-20 21:39 +08:00 . v0.1.2
package dongle
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
var base64UrlTest = []struct {
input string // 输入值
output string // 期望值
}{
{"", ""},
{"www.gouguoyin.cn", "d3d3LmdvdWd1b3lpbi5jbg=="},
}
func TestEncode_ByBase64URL_FromStringToString(t *testing.T) {
for index, test := range base64UrlTest {
e := Encode.FromString(test.input).ByBase64URL()
assert.Nil(t, e.Error)
assert.Equal(t, test.output, e.ToString(), "Current test id is "+strconv.Itoa(index))
}
}
func TestDecode_ByBase64URL_FromStringToString(t *testing.T) {
for index, test := range base64UrlTest {
d := Decode.FromString(test.output).ByBase64URL()
assert.Nil(t, d.Error)
assert.Equal(t, test.input, d.ToString(), "Current test id is "+strconv.Itoa(index))
}
}
func TestEncode_ByBase64URL_FromBytesToBytes(t *testing.T) {
for index, test := range base64UrlTest {
e := Encode.FromBytes([]byte(test.input)).ByBase64URL()
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.output), e.ToBytes(), "Current test id is "+strconv.Itoa(index))
}
}
func TestDecode_ByBase64URL_FromBytesToBytes(t *testing.T) {
for index, test := range base64UrlTest {
d := Decode.FromBytes([]byte(test.output)).ByBase64URL()
assert.Nil(t, d.Error)
assert.Equal(t, []byte(test.input), d.ToBytes(), "Current test id is "+strconv.Itoa(index))
}
}
func TestDecode_ByBase64URL_Error(t *testing.T) {
d1 := Decode.FromString("xxxxxx").ByBase64URL()
assert.Equal(t, invalidCiphertextError("base64URL"), d1.Error)
d2 := Decode.FromBytes([]byte("xxxxxx")).ByBase64URL()
assert.Equal(t, invalidCiphertextError("base64URL"), d2.Error)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jangocheng/dongle.git
git@gitee.com:jangocheng/dongle.git
jangocheng
dongle
dongle
master

搜索帮助