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