Skip to content

Commit 1d85709

Browse files
lpcoxCopilot
andcommitted
fix: replace Docker-dependent integration tests with mock HTTP backends
TestBinaryInvocation_RoutedMode and TestBinaryInvocation_UnifiedMode were using 'docker run alpine:latest echo' which fails in CI environments where Docker image pulls are blocked by firewall rules. Replaced with in-process mock MCP HTTP backends (using the existing createMinimalMockMCPBackend helper) and JSON stdin config, matching the pattern used by other integration tests. Co-authored-by: Copilot <[email protected]>
1 parent 4460784 commit 1d85709

1 file changed

Lines changed: 47 additions & 27 deletions

File tree

test/integration/binary_test.go

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,53 @@ func TestBinaryInvocation_RoutedMode(t *testing.T) {
2525
t.Skip("Skipping binary integration test in short mode")
2626
}
2727

28-
// Find the binary
2928
binaryPath := findBinary(t)
3029
t.Logf("Using binary: %s", binaryPath)
3130

32-
// Create a temporary config file
33-
configFile := createTempConfig(t, map[string]interface{}{
34-
"testserver": map[string]interface{}{
35-
"command": "docker",
36-
"args": []string{"run", "--rm", "-i", "alpine:latest", "echo"},
37-
},
38-
})
39-
defer os.Remove(configFile)
31+
// Use an in-process mock backend to avoid Docker dependency
32+
mockBackend := createMinimalMockMCPBackend(t)
33+
defer mockBackend.Close()
4034

41-
// Start the server process
4235
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
4336
defer cancel()
4437

45-
port := "13001" // Use a specific port for testing
38+
port := "13001"
4639
cmd := exec.CommandContext(ctx, binaryPath,
47-
"--config", configFile,
40+
"--config-stdin",
4841
"--listen", "127.0.0.1:"+port,
4942
"--routed",
5043
)
5144

52-
// Capture output for debugging
45+
configJSON := map[string]interface{}{
46+
"mcpServers": map[string]interface{}{
47+
"testserver": map[string]interface{}{
48+
"type": "http",
49+
"url": mockBackend.URL + "/mcp",
50+
},
51+
},
52+
"gateway": map[string]interface{}{
53+
"port": 13001,
54+
"domain": "localhost",
55+
"apiKey": "test-token",
56+
},
57+
}
58+
configBytes, _ := json.Marshal(configJSON)
59+
5360
var stdout, stderr bytes.Buffer
61+
cmd.Stdin = bytes.NewReader(configBytes)
5462
cmd.Stdout = &stdout
5563
cmd.Stderr = &stderr
5664

5765
if err := cmd.Start(); err != nil {
5866
t.Fatalf("Failed to start server: %v", err)
5967
}
6068

61-
// Ensure the process is killed at the end
6269
defer func() {
6370
if cmd.Process != nil {
6471
cmd.Process.Kill()
6572
}
6673
}()
6774

68-
// Wait for server to start
6975
serverURL := "http://127.0.0.1:" + port
7076
if !waitForServer(t, serverURL+"/health", 10*time.Second) {
7177
t.Logf("STDOUT: %s", stdout.String())
@@ -130,29 +136,43 @@ func TestBinaryInvocation_UnifiedMode(t *testing.T) {
130136
binaryPath := findBinary(t)
131137
t.Logf("Using binary: %s", binaryPath)
132138

133-
configFile := createTempConfig(t, map[string]interface{}{
134-
"backend1": map[string]interface{}{
135-
"command": "docker",
136-
"args": []string{"run", "--rm", "-i", "alpine:latest", "echo"},
137-
},
138-
"backend2": map[string]interface{}{
139-
"command": "docker",
140-
"args": []string{"run", "--rm", "-i", "alpine:latest", "echo"},
141-
},
142-
})
143-
defer os.Remove(configFile)
139+
// Use in-process mock backends to avoid Docker dependency
140+
mockBackend1 := createMinimalMockMCPBackend(t)
141+
defer mockBackend1.Close()
142+
mockBackend2 := createMinimalMockMCPBackend(t)
143+
defer mockBackend2.Close()
144144

145145
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
146146
defer cancel()
147147

148148
port := "13002"
149149
cmd := exec.CommandContext(ctx, binaryPath,
150-
"--config", configFile,
150+
"--config-stdin",
151151
"--listen", "127.0.0.1:"+port,
152152
"--unified",
153153
)
154154

155+
configJSON := map[string]interface{}{
156+
"mcpServers": map[string]interface{}{
157+
"backend1": map[string]interface{}{
158+
"type": "http",
159+
"url": mockBackend1.URL + "/mcp",
160+
},
161+
"backend2": map[string]interface{}{
162+
"type": "http",
163+
"url": mockBackend2.URL + "/mcp",
164+
},
165+
},
166+
"gateway": map[string]interface{}{
167+
"port": 13002,
168+
"domain": "localhost",
169+
"apiKey": "test-token",
170+
},
171+
}
172+
configBytes, _ := json.Marshal(configJSON)
173+
155174
var stdout, stderr bytes.Buffer
175+
cmd.Stdin = bytes.NewReader(configBytes)
156176
cmd.Stdout = &stdout
157177
cmd.Stderr = &stderr
158178

0 commit comments

Comments
 (0)