加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sha1_test.go 1013 Bytes
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2022-11-29 22:28 . 统一单元测试格式
package dongle
import (
"github.com/stretchr/testify/assert"
"strconv"
"testing"
)
var sha1Test = []struct {
input string
toHex string
toBase64 string
}{
{"", "", ""},
{"hello world", "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed", "Kq5sNclPz7QV2+lfQIuc6R7oRu0="},
}
func TestEncrypt_BySha1_ToString(t *testing.T) {
for index, test := range sha1Test {
e := Encrypt.FromString(test.input).BySha1()
assert.Nil(t, e.Error)
assert.Equal(t, test.toHex, e.ToHexString(), "Current test index is "+strconv.Itoa(index))
assert.Equal(t, test.toBase64, e.ToBase64String(), "Current test index is "+strconv.Itoa(index))
}
}
func TestEncrypt_BySha1_ToBytes(t *testing.T) {
for index, test := range sha1Test {
e := Encrypt.FromBytes([]byte(test.input)).BySha1()
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.toHex), e.ToHexBytes(), "Current test index is "+strconv.Itoa(index))
assert.Equal(t, []byte(test.toBase64), e.ToBase64Bytes(), "Current test index is "+strconv.Itoa(index))
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化