gf/g/crypto/gsha1/gsha1_test.go

63 lines
1.3 KiB
Go
Raw Normal View History

2019-04-05 17:11:03 +08:00
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// go test *.go -bench=".*"
package gsha1_test
import (
"os"
"testing"
"github.com/gogf/gf/g/crypto/gsha1"
"github.com/gogf/gf/g/test/gtest"
)
type user struct {
name string
password string
age int
}
func TestEncrypt(t *testing.T) {
gtest.Case(t, func() {
user := &user{
name: "派大星",
password: "123456",
age: 23,
}
encrypt := gsha1.Encrypt(user)
gtest.AssertNE(encrypt, "")
})
2019-04-06 12:18:51 +08:00
gtest.Case(t, func() {
s := gsha1.Encrypt("pibigstar")
gtest.AssertNE(s, "")
})
2019-04-05 17:11:03 +08:00
}
func TestEncryptString(t *testing.T) {
gtest.Case(t, func() {
s := gsha1.EncryptString("pibigstar")
gtest.AssertNE(s, "")
})
}
func TestEncryptFile(t *testing.T) {
path := "test.text"
2019-04-06 15:06:42 +08:00
errPath := "err.text"
2019-04-05 17:11:03 +08:00
gtest.Case(t, func() {
file, err := os.Create(path)
gtest.Assert(err, nil)
defer file.Close()
file.Write([]byte("Hello Go Frame"))
encryptFile := gsha1.EncryptFile(path)
gtest.AssertNE(encryptFile, "")
2019-04-06 15:06:42 +08:00
errEncrypt := gsha1.EncryptFile(errPath)
gtest.AssertEQ(errEncrypt,"")
2019-04-05 17:11:03 +08:00
})
2019-04-06 12:18:51 +08:00
defer os.Remove(path)
2019-04-05 17:11:03 +08:00
}