缓存策略增加预热超时时间设置(默认20分钟)

This commit is contained in:
GoEdgeLab
2023-08-06 17:07:48 +08:00
parent 8d2847afed
commit 1ebf3cbdce
6 changed files with 175 additions and 27 deletions

View File

@@ -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))
}