mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? Log softassert warnings if dynamic config settings are registered with default values with shared structure. ## Why? This is very likely unintended and may lead to unexpected behavior of settings (values will be parsed on top of a copy of the default). ## How did you test it? - [x] run locally and tested manually - [x] added new unit test(s)
42 lines
969 B
Go
42 lines
969 B
Go
package dynamicconfig
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestHasSharedStructure(t *testing.T) {
|
|
var v any = 3
|
|
assert.Empty(t, hasSharedStructure(reflect.ValueOf(v), "root"))
|
|
|
|
v = struct {
|
|
i int
|
|
s string
|
|
c struct{ p *string }
|
|
}{i: 5, s: "hi"}
|
|
assert.Empty(t, hasSharedStructure(reflect.ValueOf(v), "root"))
|
|
|
|
v = [5]*float64{nil, nil, nil, nil, nil}
|
|
assert.Empty(t, hasSharedStructure(reflect.ValueOf(v), "root"))
|
|
|
|
f := float64(35.124)
|
|
v = [5]*float64{nil, nil, &f, nil, nil}
|
|
assert.Equal(t, "root.[2]", hasSharedStructure(reflect.ValueOf(v), "root"))
|
|
|
|
v = []byte(nil)
|
|
assert.Empty(t, hasSharedStructure(reflect.ValueOf(v), "root"))
|
|
|
|
v = []byte{}
|
|
assert.Equal(t, "root", hasSharedStructure(reflect.ValueOf(v), "root"))
|
|
|
|
str := "test"
|
|
v = struct {
|
|
i int
|
|
s string
|
|
c struct{ p *string }
|
|
}{c: struct{ p *string }{p: &str}}
|
|
assert.Equal(t, "root.c.p", hasSharedStructure(reflect.ValueOf(v), "root"))
|
|
}
|