[fix] unit-test
This commit is contained in:
parent
355ae10dcf
commit
84279e9bfc
2 changed files with 13 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package i18n
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -76,7 +77,9 @@ func Load(cfg config.Config) error {
|
|||
func Trans(langName string, widgets []string, data interface{}) (interface{}, error) {
|
||||
|
||||
// Get From cache
|
||||
key := fmt.Sprintf("%s::%s", langName, strings.Join(widgets, "::"))
|
||||
hash := sha256.Sum256([]byte(fmt.Sprintf("%v", data)))
|
||||
key := fmt.Sprintf("%s::%s::%s", langName, strings.Join(widgets, "::"), hash)
|
||||
|
||||
if res, has := cache.data[key]; has {
|
||||
return res, nil
|
||||
}
|
||||
|
|
@ -99,7 +102,8 @@ func Trans(langName string, widgets []string, data interface{}) (interface{}, er
|
|||
func cacheSet(dict *lang.Dict, widgets []string, value interface{}) {
|
||||
cache.mu.Lock()
|
||||
defer cache.mu.Unlock()
|
||||
key := fmt.Sprintf("%s::%s", dict.Name, strings.Join(widgets, "::"))
|
||||
hash := sha256.Sum256([]byte(fmt.Sprintf("%v", value)))
|
||||
key := fmt.Sprintf("%s::%s::%s", dict.Name, strings.Join(widgets, "::"), hash)
|
||||
cache.data[key] = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,6 +142,8 @@ func TestExport(t *testing.T) {
|
|||
|
||||
func TestProcessSetting(t *testing.T) {
|
||||
loadApp(t)
|
||||
backup := config.Conf.Lang
|
||||
config.Conf.Lang = "en-us"
|
||||
res, err := gou.NewProcess("yao.app.Setting").Exec()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -169,10 +171,14 @@ func TestProcessSetting(t *testing.T) {
|
|||
|
||||
lang := gou.NewProcess("yao.app.Setting").WithSID(setting.Sid).Lang()
|
||||
assert.Equal(t, "zh-hk", lang)
|
||||
|
||||
config.Conf.Lang = backup
|
||||
}
|
||||
|
||||
func TestProcessXgen(t *testing.T) {
|
||||
loadApp(t)
|
||||
backup := config.Conf.Lang
|
||||
config.Conf.Lang = "en-us"
|
||||
res, err := gou.NewProcess("yao.app.Xgen").Exec()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -207,7 +213,7 @@ func TestProcessXgen(t *testing.T) {
|
|||
|
||||
lang := gou.NewProcess("yao.app.Setting").WithSID(xgen2.Get("sid").(string)).Lang()
|
||||
assert.Equal(t, "zh-hk", lang)
|
||||
|
||||
config.Conf.Lang = backup
|
||||
}
|
||||
|
||||
func TestProcessMenu(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue