[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:
		
							parent
							
								
									4d929a9d6a
								
							
						
					
					
						commit
						6bd77b33a5
					
				| 
						 | 
				
			
			@ -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{},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
type: test
 | 
			
		||||
 | 
			
		||||
status:
 | 
			
		||||
  class: receiver
 | 
			
		||||
  stability:
 | 
			
		||||
    beta: [logs]
 | 
			
		||||
 | 
			
		||||
tests:
 | 
			
		||||
  config:
 | 
			
		||||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue