File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -42,26 +42,26 @@ type SizeConfig struct {
42
42
// Deprecated: [v0.121.0] use SizeConfig.
43
43
type MinSizeConfig struct {
44
44
// Deprecated: [v0.121.0] use SizeConfig.MinSize.
45
- MinSizeItems * int `mapstructure:"min_size_items"`
45
+ MinSizeItems int `mapstructure:"min_size_items"`
46
46
}
47
47
48
48
// Deprecated: [v0.121.0] use SizeConfig.
49
49
type MaxSizeConfig struct {
50
50
// Deprecated: [v0.121.0] use SizeConfig.MaxSize.
51
- MaxSizeItems * int `mapstructure:"max_size_items"`
51
+ MaxSizeItems int `mapstructure:"max_size_items"`
52
52
}
53
53
54
54
func (c * Config ) Unmarshal (conf * confmap.Conf ) error {
55
55
if err := conf .Unmarshal (c ); err != nil {
56
56
return err
57
57
}
58
58
59
- if c . MinSizeItems != nil {
60
- c .SizeConfig .MinSize = * c .MinSizeItems
59
+ if conf . IsSet ( "min_size_items" ) {
60
+ c .SizeConfig .MinSize = c .MinSizeItems
61
61
}
62
62
63
- if c . MaxSizeItems != nil {
64
- c .SizeConfig .MaxSize = * c .MaxSizeItems
63
+ if conf . IsSet ( "max_size_items" ) {
64
+ c .SizeConfig .MaxSize = c .MaxSizeItems
65
65
}
66
66
67
67
return nil
Original file line number Diff line number Diff line change 7
7
"testing"
8
8
9
9
"github.com/stretchr/testify/require"
10
+
11
+ "go.opentelemetry.io/collector/confmap"
10
12
)
11
13
12
14
func TestValidateConfig (t * testing.T ) {
@@ -40,3 +42,29 @@ func TestValidateSizeConfig(t *testing.T) {
40
42
}
41
43
require .EqualError (t , cfg .Validate (), "`max_size` must be greater than or equal to mix_size" )
42
44
}
45
+
46
+ func TestUnmarshalDeprecatedConfig (t * testing.T ) {
47
+ cfg := NewDefaultConfig ()
48
+ require .NoError (t , cfg .Unmarshal (confmap .NewFromStringMap (map [string ]any {
49
+ "enabled" : true ,
50
+ "flush_timeout" : 200 ,
51
+ "min_size_items" : 111 ,
52
+ "max_size_items" : 222 ,
53
+ })))
54
+ require .NoError (t , cfg .Validate ())
55
+ require .Equal (t , cfg , Config {
56
+ Enabled : true ,
57
+ FlushTimeout : 200 ,
58
+ SizeConfig : SizeConfig {
59
+ Sizer : SizerTypeItems ,
60
+ MinSize : 111 ,
61
+ MaxSize : 222 ,
62
+ },
63
+ MinSizeConfig : MinSizeConfig {
64
+ MinSizeItems : 111 ,
65
+ },
66
+ MaxSizeConfig : MaxSizeConfig {
67
+ MaxSizeItems : 222 ,
68
+ },
69
+ })
70
+ }
You can’t perform that action at this time.
0 commit comments