26 Star 238 Fork 49

golang-module/dongle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sm3_test.go 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2022-12-07 09:04 . 统一单元测试格式
package dongle
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
var sm3Tests = []struct {
input string
toHex string
toBase64 string
}{
{"", "", ""},
{"hello world", "44f0061e69fa6fdfc290c494654a05dc0c053da7e5c52b84ef93a9d67d3fff88", "RPAGHmn6b9/CkMSUZUoF3AwFPaflxSuE75Op1n0//4g="},
}
func TestSm3_Encrypt_String(t *testing.T) {
for index, test := range sm3Tests {
e := Encrypt.FromString(test.input).BySm3()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, test.toHex, e.ToHexString())
assert.Equal(t, test.toBase64, e.ToBase64String())
})
}
}
func TestSm3_Encrypt_Bytes(t *testing.T) {
for index, test := range sm3Tests {
e := Encrypt.FromBytes([]byte(test.input)).BySm3()
t.Run(fmt.Sprintf("test_%d", index), func(t *testing.T) {
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.toHex), e.ToHexBytes())
assert.Equal(t, []byte(test.toBase64), e.ToBase64Bytes())
})
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/golang-module/dongle.git
git@gitee.com:golang-module/dongle.git
golang-module
dongle
dongle
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891