Skip to content

Commit a76c8d1

Browse files
committed
make fmt. add unit test to include otlp
1 parent 3776a5c commit a76c8d1

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

translator/jsonconfig/mergeJsonUtil/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
var MergeRuleMap = map[string]mergeJsonRule.MergeRule{}
1515

1616
var ArrayOrObjectKeys = map[string]bool{
17-
"jmx": true,
17+
"jmx": true,
1818
"otlp": true,
1919
}
2020

translator/jsonconfig/mergeJsonUtil/util_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)