MCPcopy Create free account
hub / github.com/github/gh-aw / TestMergeObservabilityConfigs

Function TestMergeObservabilityConfigs

pkg/parser/import_field_extractor_test.go:530–643  ·  view source on GitHub ↗

TestMergeObservabilityConfigs verifies that multiple observability JSON blobs are merged into a single config with all OTLP endpoints in array form, with deduplication.

(t *testing.T)

Source from the content-addressed store, hash-verified

528// TestMergeObservabilityConfigs verifies that multiple observability JSON blobs are
529// merged into a single config with all OTLP endpoints in array form, with deduplication.
530func TestMergeObservabilityConfigs(t *testing.T) {
531 t.Run("empty slice returns empty string", func(t *testing.T) {
532 got := mergeObservabilityConfigs(nil)
533 assert.Empty(t, got, "nil configs should return empty string")
534
535 got = mergeObservabilityConfigs([]string{})
536 assert.Empty(t, got, "empty configs should return empty string")
537 })
538
539 t.Run("single import with string endpoint", func(t *testing.T) {
540 configs := []string{`{"otlp":{"endpoint":"https://traces.example.com:4317"}}`}
541 got := mergeObservabilityConfigs(configs)
542 require.NotEmpty(t, got, "should produce non-empty result")
543 assert.Contains(t, got, `"https://traces.example.com:4317"`, "should include the endpoint URL")
544 })
545
546 t.Run("two imports with distinct string endpoints", func(t *testing.T) {
547 configs := []string{
548 `{"otlp":{"endpoint":"https://primary.example.com:4317"}}`,
549 `{"otlp":{"endpoint":"https://secondary.example.com:4317"}}`,
550 }
551 got := mergeObservabilityConfigs(configs)
552 require.NotEmpty(t, got, "should produce merged result")
553 assert.Contains(t, got, "primary.example.com", "should include first endpoint")
554 assert.Contains(t, got, "secondary.example.com", "should include second endpoint")
555 })
556
557 t.Run("two imports with same URL deduplicates", func(t *testing.T) {
558 configs := []string{
559 `{"otlp":{"endpoint":"https://traces.example.com:4317"}}`,
560 `{"otlp":{"endpoint":"https://traces.example.com:4317"}}`,
561 }
562 got := mergeObservabilityConfigs(configs)
563 require.NotEmpty(t, got, "should produce merged result")
564 // The URL should appear only once in the output
565 count := strings.Count(got, "traces.example.com")
566 assert.Equal(t, 1, count, "duplicate URL should appear only once")
567 })
568
569 t.Run("mix of string and object notation", func(t *testing.T) {
570 configs := []string{
571 `{"otlp":{"endpoint":"https://primary.example.com:4317"}}`,
572 `{"otlp":{"endpoint":{"url":"https://secondary.example.com:4317","headers":{"X-Key":"val"}}}}`,
573 }
574 got := mergeObservabilityConfigs(configs)
575 require.NotEmpty(t, got, "should produce merged result")
576 assert.Contains(t, got, "primary.example.com", "should include first endpoint (string form)")
577 assert.Contains(t, got, "secondary.example.com", "should include second endpoint (object form)")
578 assert.Contains(t, got, "X-Key", "should preserve headers from object form")
579 })
580
581 t.Run("import with array notation contributes all endpoints", func(t *testing.T) {
582 configs := []string{
583 `{"otlp":{"endpoint":[{"url":"https://a.example.com:4317"},{"url":"https://b.example.com:4317"}]}}`,
584 }
585 got := mergeObservabilityConfigs(configs)
586 require.NotEmpty(t, got, "should produce merged result")
587 assert.Contains(t, got, "a.example.com", "should include first array endpoint")

Callers

nothing calls this directly

Calls 3

RunMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected