MCPcopy Create free account
hub / github.com/diillson/chatcli / TestLoadConfigValid

Function TestLoadConfigValid

cli/mcp/mcp_test.go:256–301  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

254}
255
256func TestLoadConfigValid(t *testing.T) {
257 dir := t.TempDir()
258 cfgPath := filepath.Join(dir, "mcp.json")
259 cfg := `{
260 "mcpServers": [
261 {"name":"srv1","command":"echo","transport":"stdio","enabled":true},
262 {"name":"srv2","command":"cat","transport":"stdio","enabled":false},
263 {"name":"srv3","command":"test","transport":"sse","url":"http://localhost:8080","enabled":true}
264 ]
265 }`
266 if err := os.WriteFile(cfgPath, []byte(cfg), 0644); err != nil {
267 t.Fatal(err)
268 }
269
270 m := NewManager(testLogger())
271 if err := m.LoadConfig(cfgPath); err != nil {
272 t.Fatal(err)
273 }
274
275 // Only enabled servers should be loaded
276 if len(m.servers) != 2 {
277 t.Fatalf("got %d servers, want 2 (only enabled)", len(m.servers))
278 }
279 if _, ok := m.servers["srv1"]; !ok {
280 t.Error("expected srv1")
281 }
282 if _, ok := m.servers["srv2"]; ok {
283 t.Error("srv2 is disabled, should not be loaded")
284 }
285 if _, ok := m.servers["srv3"]; !ok {
286 t.Error("expected srv3")
287 }
288 if m.servers["srv3"].Config.Transport != TransportSSE {
289 t.Errorf("srv3 transport = %q, want sse", m.servers["srv3"].Config.Transport)
290 }
291 // Servers should be registered as Starting=true so /mcp status shows
292 // "iniciando…" while StartAll runs in the background.
293 for name, conn := range m.servers {
294 if !conn.Status.Starting {
295 t.Errorf("server %q: Status.Starting=false, want true after LoadConfig", name)
296 }
297 if conn.Status.Connected {
298 t.Errorf("server %q: Status.Connected=true before StartAll", name)
299 }
300 }
301}
302
303// TestStartAllRecordsLastError verifies that a server failing to start
304// surfaces the error on Status.LastError (not just in logs) so /mcp

Callers

nothing calls this directly

Calls 5

LoadConfigMethod · 0.95
ErrorfMethod · 0.80
NewManagerFunction · 0.70
testLoggerFunction · 0.70
ErrorMethod · 0.65

Tested by

no test coverage detected