Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions internal/tracing/resolve_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: " ",
Expand Down Expand Up @@ -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)
}