Skip to content

Commit e81f5cd

Browse files
authored
Merge pull request #144 from githubnext/copilot/add-integration-test-http-mcp-server
2 parents 2e8c29f + b6b2ea0 commit e81f5cd

2 files changed

Lines changed: 376 additions & 29 deletions

File tree

internal/server/health_test.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,50 @@ func TestHealthEndpoint_RoutedMode(t *testing.T) {
1616
cfg := &config.Config{
1717
Servers: map[string]*config.ServerConfig{},
1818
}
19-
19+
2020
// Create unified server
2121
ctx := context.Background()
2222
us, err := NewUnified(ctx, cfg)
2323
if err != nil {
2424
t.Fatalf("Failed to create unified server: %v", err)
2525
}
2626
defer us.Close()
27-
27+
2828
// Create HTTP server
2929
httpServer := CreateHTTPServerForRoutedMode(":0", us, "")
30-
30+
3131
// Create test request
3232
req := httptest.NewRequest("GET", "/health", nil)
3333
w := httptest.NewRecorder()
34-
34+
3535
// Execute request
3636
httpServer.Handler.ServeHTTP(w, req)
37-
37+
3838
// Check status code
3939
if w.Code != http.StatusOK {
4040
t.Errorf("Expected status 200, got %d", w.Code)
4141
}
42-
42+
4343
// Check content type
4444
contentType := w.Header().Get("Content-Type")
4545
if contentType != "application/json" {
4646
t.Errorf("Expected Content-Type 'application/json', got '%s'", contentType)
4747
}
48-
48+
4949
// Check response body
5050
var response map[string]string
5151
if err := json.NewDecoder(w.Body).Decode(&response); err != nil {
5252
t.Fatalf("Failed to decode JSON response: %v", err)
5353
}
54-
54+
5555
if response["status"] != "ok" {
5656
t.Errorf("Expected status 'ok', got '%s'", response["status"])
5757
}
58-
58+
5959
if response["protocolVersion"] != MCPProtocolVersion {
6060
t.Errorf("Expected protocolVersion '%s', got '%s'", MCPProtocolVersion, response["protocolVersion"])
6161
}
62-
62+
6363
if response["version"] == "" {
6464
t.Error("Expected version to be non-empty")
6565
}
@@ -71,50 +71,50 @@ func TestHealthEndpoint_UnifiedMode(t *testing.T) {
7171
cfg := &config.Config{
7272
Servers: map[string]*config.ServerConfig{},
7373
}
74-
74+
7575
// Create unified server
7676
ctx := context.Background()
7777
us, err := NewUnified(ctx, cfg)
7878
if err != nil {
7979
t.Fatalf("Failed to create unified server: %v", err)
8080
}
8181
defer us.Close()
82-
82+
8383
// Create HTTP server
8484
httpServer := CreateHTTPServerForMCP(":0", us, "")
85-
85+
8686
// Create test request
8787
req := httptest.NewRequest("GET", "/health", nil)
8888
w := httptest.NewRecorder()
89-
89+
9090
// Execute request
9191
httpServer.Handler.ServeHTTP(w, req)
92-
92+
9393
// Check status code
9494
if w.Code != http.StatusOK {
9595
t.Errorf("Expected status 200, got %d", w.Code)
9696
}
97-
97+
9898
// Check content type
9999
contentType := w.Header().Get("Content-Type")
100100
if contentType != "application/json" {
101101
t.Errorf("Expected Content-Type 'application/json', got '%s'", contentType)
102102
}
103-
103+
104104
// Check response body
105105
var response map[string]string
106106
if err := json.NewDecoder(w.Body).Decode(&response); err != nil {
107107
t.Fatalf("Failed to decode JSON response: %v", err)
108108
}
109-
109+
110110
if response["status"] != "ok" {
111111
t.Errorf("Expected status 'ok', got '%s'", response["status"])
112112
}
113-
113+
114114
if response["protocolVersion"] != MCPProtocolVersion {
115115
t.Errorf("Expected protocolVersion '%s', got '%s'", MCPProtocolVersion, response["protocolVersion"])
116116
}
117-
117+
118118
if response["version"] == "" {
119119
t.Error("Expected version to be non-empty")
120120
}
@@ -126,44 +126,44 @@ func TestHealthEndpoint_NoAuth(t *testing.T) {
126126
cfg := &config.Config{
127127
Servers: map[string]*config.ServerConfig{},
128128
}
129-
129+
130130
// Create unified server
131131
ctx := context.Background()
132132
us, err := NewUnified(ctx, cfg)
133133
if err != nil {
134134
t.Fatalf("Failed to create unified server: %v", err)
135135
}
136136
defer us.Close()
137-
137+
138138
// Create HTTP server WITH API key (health should still work without auth)
139139
httpServer := CreateHTTPServerForRoutedMode(":0", us, "test-api-key")
140-
140+
141141
// Create test request WITHOUT Authorization header
142142
req := httptest.NewRequest("GET", "/health", nil)
143143
w := httptest.NewRecorder()
144-
144+
145145
// Execute request
146146
httpServer.Handler.ServeHTTP(w, req)
147-
147+
148148
// Health endpoint should work without auth
149149
if w.Code != http.StatusOK {
150150
t.Errorf("Expected status 200 (health should not require auth), got %d", w.Code)
151151
}
152-
152+
153153
// Verify JSON response
154154
var response map[string]string
155155
if err := json.NewDecoder(w.Body).Decode(&response); err != nil {
156156
t.Fatalf("Failed to decode JSON response: %v", err)
157157
}
158-
158+
159159
if response["status"] != "ok" {
160160
t.Errorf("Expected status 'ok', got '%s'", response["status"])
161161
}
162-
162+
163163
if response["protocolVersion"] != MCPProtocolVersion {
164164
t.Errorf("Expected protocolVersion '%s', got '%s'", MCPProtocolVersion, response["protocolVersion"])
165165
}
166-
166+
167167
if response["version"] == "" {
168168
t.Error("Expected version to be non-empty")
169169
}

0 commit comments

Comments
 (0)