Skip to content

Commit 6bd77b3

Browse files
authored
[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`.
1 parent 4d929a9 commit 6bd77b3

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

cmd/mdatagen/internal/loader_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,22 @@ func TestLoadMetadata(t *testing.T) {
371371
},
372372
},
373373
},
374+
{
375+
name: "testdata/empty_test_config.yaml",
376+
want: Metadata{
377+
Type: "test",
378+
GeneratedPackageName: "metadata",
379+
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal",
380+
ShortFolderName: "testdata",
381+
Tests: Tests{Host: "componenttest.NewNopHost()"},
382+
Status: &Status{
383+
Class: "receiver",
384+
Stability: map[component.StabilityLevel][]string{
385+
component.StabilityLevelBeta: {"logs"},
386+
},
387+
},
388+
},
389+
},
374390
{
375391
name: "testdata/invalid_type_rattr.yaml",
376392
want: Metadata{},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type: test
2+
3+
status:
4+
class: receiver
5+
stability:
6+
beta: [logs]
7+
8+
tests:
9+
config:

confmap/confmap_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ func TestToStringMap(t *testing.T) {
9999
}
100100
}
101101

102+
type testConfigAny struct {
103+
AnyField any `mapstructure:"any_field"`
104+
}
105+
106+
func TestNilToAnyField(t *testing.T) {
107+
stringMap := map[string]any{
108+
"any_field": nil,
109+
}
110+
conf := NewFromStringMap(stringMap)
111+
cfg := &testConfigAny{}
112+
require.NoError(t, conf.Unmarshal(cfg))
113+
assert.Nil(t, cfg.AnyField)
114+
}
115+
102116
func TestExpandNilStructPointersHookFunc(t *testing.T) {
103117
stringMap := map[string]any{
104118
"boolean": nil,

0 commit comments

Comments
 (0)