@@ -10,6 +10,200 @@ 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+ wantErr string
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+ wantErr : "field exporter in BatchLogRecordProcessor: required" ,
45+ },
46+ {
47+ name : "invalid data" ,
48+ jsonConfig : []byte (`{:2000}` ),
49+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: !!str str" ),
50+ wantErr : "unmarshaling error BatchLogRecordProcessor" ,
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+ wantErr : "field export_timeout: must be >= 0" ,
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+ wantErr : "field max_export_batch_size: must be > 0" ,
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+ wantErr : "field max_export_batch_size: must be > 0" ,
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+ wantErr : "field max_queue_size: must be > 0" ,
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+ wantErr : "field max_queue_size: must be > 0" ,
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+ wantErr : "field schedule_delay: must be >= 0" ,
87+ },
88+ } {
89+ t .Run (tt .name , func (t * testing.T ) {
90+ bsp := BatchLogRecordProcessor {}
91+ err := bsp .UnmarshalJSON (tt .jsonConfig )
92+ if tt .wantErr != "" {
93+ require .Error (t , err )
94+ require .Contains (t , err .Error (), tt .wantErr )
95+ } else {
96+ require .NoError (t , err )
97+ }
98+ bsp = BatchLogRecordProcessor {}
99+ err = yaml .Unmarshal (tt .yamlConfig , & bsp )
100+ if tt .wantErr != "" {
101+ require .Error (t , err )
102+ require .Contains (t , err .Error (), tt .wantErr )
103+ } else {
104+ require .NoError (t , err )
105+ }
106+ })
107+ }
108+ }
109+
110+ func TestUnmarshalBatchSpanProcessor (t * testing.T ) {
111+ for _ , tt := range []struct {
112+ name string
113+ yamlConfig []byte
114+ jsonConfig []byte
115+ wantErr string
116+ }{
117+ {
118+ name : "valid with console exporter" ,
119+ jsonConfig : []byte (`{"exporter":{"console":{}}}` ),
120+ yamlConfig : []byte ("exporter:\n console: {}" ),
121+ },
122+ {
123+ name : "valid with all fields positive" ,
124+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":5000,"max_export_batch_size":512,"max_queue_size":2048,"schedule_delay":1000}` ),
125+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: 5000\n max_export_batch_size: 512\n max_queue_size: 2048\n schedule_delay: 1000" ),
126+ },
127+ {
128+ name : "valid with zero export_timeout" ,
129+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":0}` ),
130+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: 0" ),
131+ },
132+ {
133+ name : "valid with zero schedule_delay" ,
134+ jsonConfig : []byte (`{"exporter":{"console":{}},"schedule_delay":0}` ),
135+ yamlConfig : []byte ("exporter:\n console: {}\n schedule_delay: 0" ),
136+ },
137+ {
138+ name : "missing required exporter field" ,
139+ jsonConfig : []byte (`{}` ),
140+ yamlConfig : []byte ("{}" ),
141+ wantErr : "field exporter in BatchSpanProcessor: required" ,
142+ },
143+ {
144+ name : "invalid data" ,
145+ jsonConfig : []byte (`{:2000}` ),
146+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: !!str str" ),
147+ wantErr : "unmarshaling error BatchSpanProcessor" ,
148+ },
149+ {
150+ name : "invalid export_timeout negative" ,
151+ jsonConfig : []byte (`{"exporter":{"console":{}},"export_timeout":-1}` ),
152+ yamlConfig : []byte ("exporter:\n console: {}\n export_timeout: -1" ),
153+ wantErr : "field export_timeout: must be >= 0" ,
154+ },
155+ {
156+ name : "invalid max_export_batch_size zero" ,
157+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_export_batch_size":0}` ),
158+ yamlConfig : []byte ("exporter:\n console: {}\n max_export_batch_size: 0" ),
159+ wantErr : "field max_export_batch_size: must be > 0" ,
160+ },
161+ {
162+ name : "invalid max_export_batch_size negative" ,
163+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_export_batch_size":-1}` ),
164+ yamlConfig : []byte ("exporter:\n console: {}\n max_export_batch_size: -1" ),
165+ wantErr : "field max_export_batch_size: must be > 0" ,
166+ },
167+ {
168+ name : "invalid max_queue_size zero" ,
169+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_queue_size":0}` ),
170+ yamlConfig : []byte ("exporter:\n console: {}\n max_queue_size: 0" ),
171+ wantErr : "field max_queue_size: must be > 0" ,
172+ },
173+ {
174+ name : "invalid max_queue_size negative" ,
175+ jsonConfig : []byte (`{"exporter":{"console":{}},"max_queue_size":-1}` ),
176+ yamlConfig : []byte ("exporter:\n console: {}\n max_queue_size: -1" ),
177+ wantErr : "field max_queue_size: must be > 0" ,
178+ },
179+ {
180+ name : "invalid schedule_delay negative" ,
181+ jsonConfig : []byte (`{"exporter":{"console":{}},"schedule_delay":-1}` ),
182+ yamlConfig : []byte ("exporter:\n console: {}\n schedule_delay: -1" ),
183+ wantErr : "field schedule_delay: must be >= 0" ,
184+ },
185+ } {
186+ t .Run (tt .name , func (t * testing.T ) {
187+ bsp := BatchSpanProcessor {}
188+ err := bsp .UnmarshalJSON (tt .jsonConfig )
189+ if tt .wantErr != "" {
190+ require .Error (t , err )
191+ require .Contains (t , err .Error (), tt .wantErr )
192+ } else {
193+ require .NoError (t , err )
194+ }
195+ bsp = BatchSpanProcessor {}
196+ err = yaml .Unmarshal (tt .yamlConfig , & bsp )
197+ if tt .wantErr != "" {
198+ require .Error (t , err )
199+ require .Contains (t , err .Error (), tt .wantErr )
200+ } else {
201+ require .NoError (t , err )
202+ }
203+ })
204+ }
205+ }
206+
13207func TestUnmarshalCardinalityLimits (t * testing.T ) {
14208 for _ , tt := range []struct {
15209 name string
0 commit comments