mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-09 19:03:50 +02:00
refactored some stuff, added healthcheck support, fixed 'include file' reload not showing in log
This commit is contained in:
@@ -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())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user