@@ -10,6 +10,182 @@ import (
1010 "go.yaml.in/yaml/v3"
1111)
1212
13+ func TestUnmarshalBatchLogRecordProcessor (t * testing.T ) {
14+ for _ , tt := range []struct {
15+ name string
16+ yamlConfig []byte
17+ jsonConfig []byte
18+ wantErrT error
19+ }{
20+ {
21+ name : "valid with console exporter" ,
22+ jsonConfig : []byte (`{"exporter":{"console":{}}}` ),
23+ yamlConfig : []byte ("exporter:\n console: {}" ),
24+ },
25+ {
26+ name : "valid with all fields positive" ,
27+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":5000,"max_export_batch_size":512,"max_queue_size":2048,"schedule_delay":1000}` ),
28+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: 5000\n max_export_batch_size: 512\n max_queue_size: 2048\n schedule_delay: 1000" ),
29+ },
30+ {
31+ name : "valid with zero export_timeout" ,
32+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":0}` ),
33+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: 0" ),
34+ },
35+ {
36+ name : "valid with zero schedule_delay" ,
37+ jsonConfig : []byte (`{"exporter":{"console":{}},"schedule_delay":0}` ),
38+ yamlConfig : []byte ("exporter:\n console: {}\n schedule_delay: 0" ),
39+ },
40+ {
41+ name : "missing required exporter field" ,
42+ jsonConfig : []byte (`{}` ),
43+ yamlConfig : []byte ("{}" ),
44+ wantErrT : newErrRequiredExporter ("BatchLogRecordProcessor" ),
45+ },
46+ {
47+ name : "invalid data" ,
48+ jsonConfig : []byte (`{:2000}` ),
49+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: !!str str" ),
50+ wantErrT : errUnmarshalingBatchLogRecordProcessor ,
51+ },
52+ {
53+ name : "invalid export_timeout negative" ,
54+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":-1}` ),
55+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: -1" ),
56+ wantErrT : newErrGreaterOrEqualZero ("export_timeout" ),
57+ },
58+ {
59+ name : "invalid max_export_batch_size zero" ,
60+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_export_batch_size":0}` ),
61+ yamlConfig : []byte ("exporter:\n console: {}\n max_export_batch_size: 0" ),
62+ wantErrT : newErrGreaterThanZero ("max_export_batch_size" ),
63+ },
64+ {
65+ name : "invalid max_export_batch_size negative" ,
66+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_export_batch_size":-1}` ),
67+ yamlConfig : []byte ("exporter:\n console: {}\n max_export_batch_size: -1" ),
68+ wantErrT : newErrGreaterThanZero ("max_export_batch_size" ),
69+ },
70+ {
71+ name : "invalid max_queue_size zero" ,
72+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_queue_size":0}` ),
73+ yamlConfig : []byte ("exporter:\n console: {}\n max_queue_size: 0" ),
74+ wantErrT : newErrGreaterThanZero ("max_queue_size" ),
75+ },
76+ {
77+ name : "invalid max_queue_size negative" ,
78+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_queue_size":-1}` ),
79+ yamlConfig : []byte ("exporter:\n console: {}\n max_queue_size: -1" ),
80+ wantErrT : newErrGreaterThanZero ("max_queue_size" ),
81+ },
82+ {
83+ name : "invalid schedule_delay negative" ,
84+ jsonConfig : []byte (`{"exporter":{"console":{}},"schedule_delay":-1}` ),
85+ yamlConfig : []byte ("exporter:\n console: {}\n schedule_delay: -1" ),
86+ wantErrT : newErrGreaterOrEqualZero ("schedule_delay" ),
87+ },
88+ } {
89+ t .Run (tt .name , func (t * testing.T ) {
90+ cl := BatchLogRecordProcessor {}
91+ err := cl .UnmarshalJSON (tt .jsonConfig )
92+ assert .ErrorIs (t , err , tt .wantErrT )
93+
94+ cl = BatchLogRecordProcessor {}
95+ err = yaml .Unmarshal (tt .yamlConfig , & cl )
96+ assert .ErrorIs (t , err , tt .wantErrT )
97+ })
98+ }
99+ }
100+
101+ func TestUnmarshalBatchSpanProcessor (t * testing.T ) {
102+ for _ , tt := range []struct {
103+ name string
104+ yamlConfig []byte
105+ jsonConfig []byte
106+ wantErrT error
107+ }{
108+ {
109+ name : "valid with console exporter" ,
110+ jsonConfig : []byte (`{"exporter":{"console":{}}}` ),
111+ yamlConfig : []byte ("exporter:\n console: {}" ),
112+ },
113+ {
114+ name : "valid with all fields positive" ,
115+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":5000,"max_export_batch_size":512,"max_queue_size":2048,"schedule_delay":1000}` ),
116+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: 5000\n max_export_batch_size: 512\n max_queue_size: 2048\n schedule_delay: 1000" ),
117+ },
118+ {
119+ name : "valid with zero export_timeout" ,
120+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":0}` ),
121+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: 0" ),
122+ },
123+ {
124+ name : "valid with zero schedule_delay" ,
125+ jsonConfig : []byte (`{"exporter":{"console":{}},"schedule_delay":0}` ),
126+ yamlConfig : []byte ("exporter:\n console: {}\n schedule_delay: 0" ),
127+ },
128+ {
129+ name : "missing required exporter field" ,
130+ jsonConfig : []byte (`{}` ),
131+ yamlConfig : []byte ("{}" ),
132+ wantErrT : newErrRequiredExporter ("BatchSpanProcessor" ),
133+ },
134+ {
135+ name : "invalid data" ,
136+ jsonConfig : []byte (`{:2000}` ),
137+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: !!str str" ),
138+ wantErrT : errUnmarshalingBatchSpanProcessor ,
139+ },
140+ {
141+ name : "invalid export_timeout negative" ,
142+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":-1}` ),
143+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: -1" ),
144+ wantErrT : newErrGreaterOrEqualZero ("export_timeout" ),
145+ },
146+ {
147+ name : "invalid max_export_batch_size zero" ,
148+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_export_batch_size":0}` ),
149+ yamlConfig : []byte ("exporter:\n console: {}\n max_export_batch_size: 0" ),
150+ wantErrT : newErrGreaterThanZero ("max_export_batch_size" ),
151+ },
152+ {
153+ name : "invalid max_export_batch_size negative" ,
154+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_export_batch_size":-1}` ),
155+ yamlConfig : []byte ("exporter:\n console: {}\n max_export_batch_size: -1" ),
156+ wantErrT : newErrGreaterThanZero ("max_export_batch_size" ),
157+ },
158+ {
159+ name : "invalid max_queue_size zero" ,
160+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_queue_size":0}` ),
161+ yamlConfig : []byte ("exporter:\n console: {}\n max_queue_size: 0" ),
162+ wantErrT : newErrGreaterThanZero ("max_queue_size" ),
163+ },
164+ {
165+ name : "invalid max_queue_size negative" ,
166+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_queue_size":-1}` ),
167+ yamlConfig : []byte ("exporter:\n console: {}\n max_queue_size: -1" ),
168+ wantErrT : newErrGreaterThanZero ("max_queue_size" ),
169+ },
170+ {
171+ name : "invalid schedule_delay negative" ,
172+ jsonConfig : []byte (`{"exporter":{"console":{}},"schedule_delay":-1}` ),
173+ yamlConfig : []byte ("exporter:\n console: {}\n schedule_delay: -1" ),
174+ wantErrT : newErrGreaterOrEqualZero ("schedule_delay" ),
175+ },
176+ } {
177+ t .Run (tt .name , func (t * testing.T ) {
178+ cl := BatchSpanProcessor {}
179+ err := cl .UnmarshalJSON (tt .jsonConfig )
180+ assert .ErrorIs (t , err , tt .wantErrT )
181+
182+ cl = BatchSpanProcessor {}
183+ err = yaml .Unmarshal (tt .yamlConfig , & cl )
184+ assert .ErrorIs (t , err , tt .wantErrT )
185+ })
186+ }
187+ }
188+
13189func TestUnmarshalCardinalityLimits (t * testing.T ) {
14190 for _ , tt := range []struct {
15191 name string
0 commit comments