2 Star 0 Fork 0

mirrors_qiniu/snippets

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
id_test.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
xushiwei 提交于 2020-06-16 09:57 . init
package main
import (
"fmt"
"testing"
)
func TestValidateID(t *testing.T) {
for _, tc := range []struct {
in string
want error
}{
{
in: "D9L6MbPfE4",
want: nil,
},
{
in: "ABZdez09-_",
want: nil,
},
{
in: "N_M_YelfGeR",
want: nil,
},
{
in: "Abc",
want: fmt.Errorf("id length is 3 instead of 10 or 11"),
},
{
in: "Abc?q=1235",
want: fmt.Errorf("id contains unexpected character '?'"),
},
{
in: "../../file",
want: fmt.Errorf("id contains unexpected character '.'"),
},
{
in: "Heya世界",
want: fmt.Errorf(`id contains unexpected character '\u00e4'`),
},
} {
got := validateID(tc.in)
if !equalError(got, tc.want) {
t.Errorf("validateID(%q) error doesn't match:\n got: %v\nwant: %v", tc.in, got, tc.want)
}
}
}
// equalError reports whether errors a and b are considered equal.
// They're equal if both are nil, or both are not nil and a.Error() == b.Error().
func equalError(a, b error) bool {
return a == nil && b == nil || a != nil && b != nil && a.Error() == b.Error()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_qiniu/snippets.git
git@gitee.com:mirrors_qiniu/snippets.git
mirrors_qiniu
snippets
snippets
master

搜索帮助