TestMCPErrorMessageStructure verifies that all error messages have consistent structure
(t *testing.T)
| 334 | |
| 335 | // TestMCPErrorMessageStructure verifies that all error messages have consistent structure |
| 336 | func TestMCPErrorMessageStructure(t *testing.T) { |
| 337 | testCases := []struct { |
| 338 | description string |
| 339 | toolConfig map[string]any |
| 340 | toolName string |
| 341 | }{ |
| 342 | { |
| 343 | description: "unknown property", |
| 344 | toolConfig: map[string]any{ |
| 345 | "command": "npx", |
| 346 | "invalid": "value", |
| 347 | }, |
| 348 | toolName: "test-tool", |
| 349 | }, |
| 350 | { |
| 351 | description: "missing required fields", |
| 352 | toolConfig: map[string]any{ |
| 353 | "args": []string{"test"}, |
| 354 | }, |
| 355 | toolName: "test-tool", |
| 356 | }, |
| 357 | { |
| 358 | description: "http without url", |
| 359 | toolConfig: map[string]any{ |
| 360 | "type": "http", |
| 361 | }, |
| 362 | toolName: "test-tool", |
| 363 | }, |
| 364 | { |
| 365 | description: "unsupported type", |
| 366 | toolConfig: map[string]any{ |
| 367 | "type": "invalid", |
| 368 | "command": "test", |
| 369 | }, |
| 370 | toolName: "test-tool", |
| 371 | }, |
| 372 | } |
| 373 | |
| 374 | for _, tc := range testCases { |
| 375 | t.Run(tc.description, func(t *testing.T) { |
| 376 | _, err := getMCPConfig(tc.toolConfig, tc.toolName) |
| 377 | if err == nil { |
| 378 | t.Fatal("Expected error but got none") |
| 379 | } |
| 380 | |
| 381 | errMsg := err.Error() |
| 382 | |
| 383 | // Count newlines to verify multi-line example |
| 384 | newlineCount := strings.Count(errMsg, "\n") |
| 385 | if !strings.Contains(errMsg, "Example:") { |
| 386 | // Some errors might not have examples in all cases |
| 387 | return |
| 388 | } |
| 389 | |
| 390 | if newlineCount < 2 { |
| 391 | t.Error("Multi-line examples should have at least 2 newlines for YAML structure") |
| 392 | } |
| 393 |
nothing calls this directly
no test coverage detected