Skip to content

Commit 4ea7589

Browse files
committed
Refactor integration test to use explicit endpoint field
Address code review feedback by replacing string-based test logic with explicit struct fields. Instead of using tc.name to determine the endpoint for streamable HTTP tests, add an 'endpoint' field to the test case struct. This makes the test logic more explicit and less fragile, following better testing practices by avoiding logic based on test names. Changes: - Add 'endpoint' field to test case struct for streamable-http transport - Remove tc.name == 'Streamable HTTP with custom path' logic - Use tc.endpoint directly for streamable HTTP server setup - Maintain same test coverage with cleaner, more maintainable code
1 parent 3fd5f00 commit 4ea7589

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pkg/mcp/parser_integration_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestParsingMiddlewareWithRealMCPClients(t *testing.T) {
2323
name string
2424
ssePath string
2525
messagePath string
26+
endpoint string // for streamable-http transport
2627
transport string // "sse" or "streamable-http"
2728
}{
2829
{
@@ -45,10 +46,12 @@ func TestParsingMiddlewareWithRealMCPClients(t *testing.T) {
4546
},
4647
{
4748
name: "Streamable HTTP with standard path",
49+
endpoint: "/mcp",
4850
transport: "streamable-http",
4951
},
5052
{
5153
name: "Streamable HTTP with custom path",
54+
endpoint: "/api/v1/rpc",
5255
transport: "streamable-http",
5356
},
5457
}
@@ -80,13 +83,9 @@ func TestParsingMiddlewareWithRealMCPClients(t *testing.T) {
8083
testServerURL = setupSSEServer(t, mcpServer, tc.ssePath, tc.messagePath, parsingCaptureMiddleware)
8184
mcpClient, err = client.NewSSEMCPClient(testServerURL + tc.ssePath)
8285
} else {
83-
// For streamable HTTP, use a single endpoint
84-
endpoint := "/mcp"
85-
if tc.name == "Streamable HTTP with custom path" {
86-
endpoint = "/api/v1/rpc"
87-
}
88-
testServerURL = setupStreamableHTTPServer(t, mcpServer, endpoint, parsingCaptureMiddleware)
89-
mcpClient, err = client.NewStreamableHttpClient(testServerURL + endpoint)
86+
// For streamable HTTP, use the specified endpoint
87+
testServerURL = setupStreamableHTTPServer(t, mcpServer, tc.endpoint, parsingCaptureMiddleware)
88+
mcpClient, err = client.NewStreamableHttpClient(testServerURL + tc.endpoint)
9089
}
9190
require.NoError(t, err)
9291

0 commit comments

Comments
 (0)