mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-09 12:00:25 +08:00
缓存策略增加预热超时时间设置(默认20分钟)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"testing"
|
||||
@@ -49,3 +50,38 @@ func TestJSONClone_Slice(t *testing.T) {
|
||||
}
|
||||
logs.PrintAsJSON(newU, t)
|
||||
}
|
||||
|
||||
type jsonUserType struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
|
||||
func (this *jsonUserType) Init() error {
|
||||
if len(this.Name) < 10 {
|
||||
return errors.New("'name' too short")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestJSONDecodeConfig(t *testing.T) {
|
||||
var data = []byte(`{ "name":"Lily", "age":20, "description": "Nice" }`)
|
||||
|
||||
var u = &jsonUserType{}
|
||||
newJSON, err := utils.JSONDecodeConfig(data, u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("%+v, %s", u, string(newJSON))
|
||||
}
|
||||
|
||||
func TestJSONDecodeConfig_Validate(t *testing.T) {
|
||||
var data = []byte(`{ "name":"Lily", "age":20, "description": "Nice" }`)
|
||||
|
||||
var u = &jsonUserType{}
|
||||
|
||||
newJSON, err := utils.JSONDecodeConfig(data, u)
|
||||
if err != nil {
|
||||
t.Log("ignore error:", err) // error expected
|
||||
}
|
||||
t.Logf("%+v, %s", u, string(newJSON))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user