Skip to content

Commit

Permalink
bring back test in config as well
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Apr 21, 2024
1 parent 76b9c1f commit 4445cc4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions component/config_test.go
Expand Up @@ -12,6 +12,8 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/confmap"
)

var _ fmt.Stringer = Type{}
Expand Down Expand Up @@ -420,3 +422,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)
}

0 comments on commit 4445cc4

Please sign in to comment.