Skip to content

Commit 854bbd2

Browse files
committed
improve comment and add TestParseCommaSeparated
1 parent d45c414 commit 854bbd2

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

pkg/http/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func NewHTTPMcpHandler(cfg *HTTPServerConfig,
7777
}
7878

7979
// RegisterRoutes registers the routes for the MCP server
80+
// URL-based values take precedence over header-based values
8081
func (h *HTTPMcpHandler) RegisterRoutes(r chi.Router) {
8182
r.Use(middleware.WithRequestConfig)
8283

pkg/http/headers/parse_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package headers
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestParseCommaSeparated(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
input string
13+
expected []string
14+
}{
15+
{
16+
name: "empty string",
17+
input: "",
18+
expected: []string{},
19+
},
20+
{
21+
name: "single value",
22+
input: "foo",
23+
expected: []string{"foo"},
24+
},
25+
{
26+
name: "multiple values",
27+
input: "foo,bar,baz",
28+
expected: []string{"foo", "bar", "baz"},
29+
},
30+
{
31+
name: "whitespace trimmed",
32+
input: " foo , bar , baz ",
33+
expected: []string{"foo", "bar", "baz"},
34+
},
35+
{
36+
name: "empty values filtered",
37+
input: "foo,,bar,",
38+
expected: []string{"foo", "bar"},
39+
},
40+
{
41+
name: "only commas",
42+
input: ",,,",
43+
expected: []string{},
44+
},
45+
{
46+
name: "whitespace only values filtered",
47+
input: "foo, ,bar",
48+
expected: []string{"foo", "bar"},
49+
},
50+
}
51+
52+
for _, tt := range tests {
53+
t.Run(tt.name, func(t *testing.T) {
54+
result := ParseCommaSeparated(tt.input)
55+
assert.Equal(t, tt.expected, result)
56+
})
57+
}
58+
}

0 commit comments

Comments
 (0)