@@ -282,14 +282,51 @@ func TestMergeArrayOrObjectConfiguration(t *testing.T) {
282282 },
283283 },
284284 },
285+ {
286+ name : "merge OTLP objects with different endpoints -> array with both" ,
287+ sourceMap : map [string ]interface {}{
288+ "otlp" : map [string ]interface {}{
289+ "endpoint" : "http://localhost:4318" ,
290+ "protocol" : "grpc" ,
291+ },
292+ },
293+ resultMap : map [string ]interface {}{
294+ "otlp" : map [string ]interface {}{
295+ "endpoint" : "http://localhost:4317" ,
296+ "protocol" : "grpc" ,
297+ },
298+ },
299+ expected : map [string ]interface {}{
300+ "otlp" : []interface {}{
301+ map [string ]interface {}{
302+ "endpoint" : "http://localhost:4317" ,
303+ "protocol" : "grpc" ,
304+ },
305+ map [string ]interface {}{
306+ "endpoint" : "http://localhost:4318" ,
307+ "protocol" : "grpc" ,
308+ },
309+ },
310+ },
311+ },
285312 }
286313
287314 for _ , tt := range tests {
288315 t .Run (tt .name , func (t * testing.T ) {
289- mergeArrayOrObjectConfiguration (tt .sourceMap , tt .resultMap , "jmx" , "/test/path/" )
316+ // Determine the key to test based on the test data
317+ key := "jmx"
318+ if _ , hasOtlp := tt .sourceMap ["otlp" ]; hasOtlp {
319+ key = "otlp"
320+ } else if _ , hasOtlp := tt .resultMap ["otlp" ]; hasOtlp {
321+ key = "otlp"
322+ }
323+
324+ mergeArrayOrObjectConfiguration (tt .sourceMap , tt .resultMap , key , "/test/path/" )
290325 if ! reflect .DeepEqual (tt .resultMap , tt .expected ) {
291326 t .Errorf ("mergeArrayOrObjectConfiguration() = %v, want %v" , tt .resultMap , tt .expected )
292327 }
293328 })
294329 }
295330}
331+
332+
0 commit comments