refactored some stuff, added healthcheck support, fixed 'include file' reload not showing in log

This commit is contained in:
yusing
2024-10-12 13:56:38 +08:00
parent 64e30f59e8
commit d47b672aa5
41 changed files with 783 additions and 421 deletions

View File

@@ -4,6 +4,7 @@ import (
"reflect"
"testing"
E "github.com/yusing/go-proxy/internal/error"
. "github.com/yusing/go-proxy/internal/utils/testing"
)
@@ -102,3 +103,48 @@ func TestStringIntConvert(t *testing.T) {
ExpectNoError(t, err.Error())
ExpectEqual(t, test.u64, uint64(127))
}
type testModel struct {
Test testType
}
type testType struct {
foo int
bar string
}
func (c *testType) ConvertFrom(v any) E.NestedError {
switch v := v.(type) {
case string:
c.bar = v
return nil
case int:
c.foo = v
return nil
default:
return E.Invalid("input type", v)
}
}
func TestConvertor(t *testing.T) {
t.Run("string", func(t *testing.T) {
m := new(testModel)
ExpectNoError(t, Deserialize(map[string]any{"Test": "bar"}, m).Error())
ExpectEqual(t, m.Test.foo, 0)
ExpectEqual(t, m.Test.bar, "bar")
})
t.Run("int", func(t *testing.T) {
m := new(testModel)
ExpectNoError(t, Deserialize(map[string]any{"Test": 123}, m).Error())
ExpectEqual(t, m.Test.foo, 123)
ExpectEqual(t, m.Test.bar, "")
})
t.Run("invalid", func(t *testing.T) {
m := new(testModel)
ExpectError(t, E.ErrInvalid, Deserialize(map[string]any{"Test": 123.456}, m).Error())
})
}