Files
tasks/common/dynamicconfig/shared_structure_test.go
David ReissandGitHub 083dbb13dc Warn on dynamic config default values with shared structure (#8176)
## 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)
2025-08-18 12:41:41 -07:00

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