[chore] Add tests loading nil to any (#12998)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

While working on #12981, I would have found it useful to have these
tests, since they surfaced a bug when enabling `DecodeNil`.
This commit is contained in:
Pablo Baeyens 2025-05-09 11:36:54 +02:00 committed by GitHub
parent 4d929a9d6a
commit 6bd77b33a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 0 deletions

View File

@ -371,6 +371,22 @@ func TestLoadMetadata(t *testing.T) {
},
},
},
{
name: "testdata/empty_test_config.yaml",
want: Metadata{
Type: "test",
GeneratedPackageName: "metadata",
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal",
ShortFolderName: "testdata",
Tests: Tests{Host: "componenttest.NewNopHost()"},
Status: &Status{
Class: "receiver",
Stability: map[component.StabilityLevel][]string{
component.StabilityLevelBeta: {"logs"},
},
},
},
},
{
name: "testdata/invalid_type_rattr.yaml",
want: Metadata{},

View File

@ -0,0 +1,9 @@
type: test
status:
class: receiver
stability:
beta: [logs]
tests:
config:

View File

@ -99,6 +99,20 @@ func TestToStringMap(t *testing.T) {
}
}
type testConfigAny struct {
AnyField any `mapstructure:"any_field"`
}
func TestNilToAnyField(t *testing.T) {
stringMap := map[string]any{
"any_field": nil,
}
conf := NewFromStringMap(stringMap)
cfg := &testConfigAny{}
require.NoError(t, conf.Unmarshal(cfg))
assert.Nil(t, cfg.AnyField)
}
func TestExpandNilStructPointersHookFunc(t *testing.T) {
stringMap := map[string]any{
"boolean": nil,