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 Mar 14, 2024
1 parent ff253a8 commit dfa57f1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions component/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -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)
}

0 comments on commit dfa57f1

Please sign in to comment.