From fd563b61e3dcf95a16ae03323f0ac7c115123343 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 14 Jun 2026 00:22:56 +0000 Subject: [PATCH] Improve tests for tracing package: add coverage for empty/whitespace JSON endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing test cases to resolve_endpoint_test.go that cover the previously-uncovered 'continue' statement in resolveJSONExtraEndpoints when a JSON array entry has an empty or whitespace-only URL field. Also add a missing 'empty string returns empty' case to TestNormalizeExtraEndpoint to make the table complete. Coverage: 97.2% → 97.5% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/tracing/resolve_endpoint_test.go | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/internal/tracing/resolve_endpoint_test.go b/internal/tracing/resolve_endpoint_test.go index 1c4bf466..cca50a16 100644 --- a/internal/tracing/resolve_endpoint_test.go +++ b/internal/tracing/resolve_endpoint_test.go @@ -225,6 +225,11 @@ func TestNormalizeExtraEndpoint(t *testing.T) { signalPath string want string }{ + { + name: "empty string returns empty", + endpoint: "", + want: "", + }, { name: "whitespace only returns empty", endpoint: " ", @@ -254,3 +259,32 @@ func TestNormalizeExtraEndpoint(t *testing.T) { }) } } + +// TestResolveExtraEndpoints_JSONArray_EmptyURL verifies that a JSON-format +// GH_AW_OTLP_ENDPOINTS entry with an empty URL field is silently skipped +// while valid entries are still returned. +func TestResolveExtraEndpoints_JSONArray_EmptyURL(t *testing.T) { + t.Setenv("GH_AW_OTLP_ENDPOINTS", `[{"url":""},{"url":"http://ep1:4318"}]`) + got := resolveExtraEndpoints(nil) + require.Len(t, got, 1) + assert.Equal(t, "http://ep1:4318/v1/traces", got[0]) +} + +// TestResolveExtraEndpoints_JSONArray_WhitespaceURL verifies that a JSON-format +// GH_AW_OTLP_ENDPOINTS entry with a whitespace-only URL field is silently skipped +// while valid entries are still returned. +func TestResolveExtraEndpoints_JSONArray_WhitespaceURL(t *testing.T) { + t.Setenv("GH_AW_OTLP_ENDPOINTS", `[{"url":" "},{"url":"http://ep1:4318"}]`) + got := resolveExtraEndpoints(nil) + require.Len(t, got, 1) + assert.Equal(t, "http://ep1:4318/v1/traces", got[0]) +} + +// TestResolveExtraEndpoints_JSONArray_AllEmptyURLsReturnsNil verifies that when +// all JSON-format GH_AW_OTLP_ENDPOINTS entries have empty or whitespace URLs, +// resolveExtraEndpoints returns nil (no valid endpoints). +func TestResolveExtraEndpoints_JSONArray_AllEmptyURLsReturnsNil(t *testing.T) { + t.Setenv("GH_AW_OTLP_ENDPOINTS", `[{"url":""},{"url":" "}]`) + got := resolveExtraEndpoints(nil) + assert.Nil(t, got) +}