代码拉取完成,页面将自动刷新
同步操作将从 dromara/dongle 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package dongle
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
var (
md5Input = "hello world"
md5HexExpected = "5eb63bbbe01eeed093cb22bb8f5acdc3"
md5Base32Expected = "L23DXO7AD3XNBE6LEK5Y6WWNYM======"
md5Base64Expected = "XrY7u+Ae7tCTyyK7j1rNww=="
)
func TestEncrypt_ByMd5_FromStringToString(t *testing.T) {
hexTests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{md5Input, md5HexExpected},
}
for index, test := range hexTests {
e := Encrypt.FromString(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToHexString(), "Current test index is "+strconv.Itoa(index))
}
base32Tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{md5Input, md5Base32Expected},
}
for index, test := range base32Tests {
e := Encrypt.FromString(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase32String(), "Current test index is "+strconv.Itoa(index))
}
base64Tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{md5Input, md5Base64Expected},
}
for index, test := range base64Tests {
e := Encrypt.FromString(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase64String(), "Current test index is "+strconv.Itoa(index))
}
}
func TestEncrypt_ByMd5_FromBytesToBytes(t *testing.T) {
hexTests := []struct {
input []byte // 输入值
expected []byte // 期望值
}{
{[]byte(""), []byte("")},
{[]byte(md5Input), []byte(md5HexExpected)},
}
for index, test := range hexTests {
e := Encrypt.FromBytes(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToHexBytes(), "Current test index is "+strconv.Itoa(index))
}
base32Tests := []struct {
input []byte // 输入值
expected []byte // 期望值
}{
{[]byte(""), []byte("")},
{[]byte(md5Input), []byte(md5Base32Expected)},
}
for index, test := range base32Tests {
e := Encrypt.FromBytes(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase32Bytes(), "Current test index is "+strconv.Itoa(index))
}
base64Tests := []struct {
input []byte // 输入值
expected []byte // 期望值
}{
{[]byte(""), []byte("")},
{[]byte(md5Input), []byte(md5Base64Expected)},
}
for index, test := range base64Tests {
e := Encrypt.FromBytes(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase64Bytes(), "Current test index is "+strconv.Itoa(index))
}
}
func TestEncrypt_ByMd5_FromFileToString(t *testing.T) {
hexTests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"./LICENSE", "c7549a87626c65bd0970e32e02f130d7"},
}
for index, test := range hexTests {
e := Encrypt.FromFile(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToHexString(), "Current test index is "+strconv.Itoa(index))
}
base32Tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"./LICENSE", "Y5KJVB3CNRS32CLQ4MXAF4JQ24======"},
}
for index, test := range base32Tests {
e := Encrypt.FromFile(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase32String(), "Current test index is "+strconv.Itoa(index))
}
base64Tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"./LICENSE", "x1Sah2JsZb0JcOMuAvEw1w=="},
}
for index, test := range base64Tests {
e := Encrypt.FromFile(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase64String(), "Current test index is "+strconv.Itoa(index))
}
}
func TestEncrypt_ByMd5_FromFileToBytes(t *testing.T) {
hexTests := []struct {
input []byte // 输入值
expected []byte // 期望值
}{
{[]byte(""), []byte("")},
{[]byte("./LICENSE"), []byte("c7549a87626c65bd0970e32e02f130d7")},
}
for index, test := range hexTests {
e := Encrypt.FromFile(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToHexBytes(), "Current test index is "+strconv.Itoa(index))
}
base32Tests := []struct {
input []byte // 输入值
expected []byte // 期望值
}{
{[]byte(""), []byte("")},
{[]byte("./LICENSE"), []byte("Y5KJVB3CNRS32CLQ4MXAF4JQ24======")},
}
for index, test := range base32Tests {
e := Encrypt.FromFile(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase32Bytes(), "Current test index is "+strconv.Itoa(index))
}
base64Tests := []struct {
input []byte // 输入值
expected []byte // 期望值
}{
{[]byte(""), []byte("")},
{[]byte("./LICENSE"), []byte("x1Sah2JsZb0JcOMuAvEw1w==")},
}
for index, test := range base64Tests {
e := Encrypt.FromFile(test.input).ByMd5()
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBase64Bytes(), "Current test index is "+strconv.Itoa(index))
}
}
func TestError_ByMd5(t *testing.T) {
file := "./demo.txt"
e := Encrypt.FromFile(file).ByMd5()
assert.Equal(t, invalidFileError(file), e.Error, "Should catch an exception")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。