From dfa57f1b71434f2c26c0e233cfd349613fc3f21b Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Thu, 14 Mar 2024 13:25:06 -0700 Subject: [PATCH] bring back test in config as well --- component/config_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/component/config_test.go b/component/config_test.go index 79651959108..fea4ba04221 100644 --- a/component/config_test.go +++ b/component/config_test.go @@ -11,6 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "go.opentelemetry.io/collector/confmap" ) var _ fmt.Stringer = Type{} @@ -417,3 +419,27 @@ func TestNewType(t *testing.T) { }) } } + +type configWithEmbeddedStruct struct { + String string `mapstructure:"string"` + Num int `mapstructure:"num"` + EmbeddedUnmarshallingConfig `mapstructure:",squash"` +} + +type EmbeddedUnmarshallingConfig struct { +} + +func (euc *EmbeddedUnmarshallingConfig) Unmarshal(_ *confmap.Conf) error { + return nil // do nothing. +} +func TestStructWithEmbeddedUnmarshaling(t *testing.T) { + cfgMap := confmap.NewFromStringMap(map[string]any{ + "string": "foo", + "num": 123, + }) + tc := &configWithEmbeddedStruct{} + err := UnmarshalConfig(cfgMap, tc) + require.NoError(t, err) + assert.Equal(t, "foo", tc.String) + assert.Equal(t, 123, tc.Num) +}