|
8 | 8 | "testing"
|
9 | 9 |
|
10 | 10 | "github.com/docker/docker/api/types/volume"
|
| 11 | + "github.com/modelcontextprotocol/go-sdk/mcp" |
11 | 12 | "github.com/stretchr/testify/assert"
|
12 | 13 | "github.com/stretchr/testify/require"
|
13 | 14 |
|
@@ -318,3 +319,55 @@ func withSampleCatalog() option {
|
318 | 319 | writeFile(t, filepath.Join(home, ".docker/mcp/catalogs/docker-mcp.yaml"), []byte(catalogContent))
|
319 | 320 | }
|
320 | 321 | }
|
| 322 | + |
| 323 | +// Unit tests for utility functions |
| 324 | + |
| 325 | +func TestCallNoToolName(t *testing.T) { |
| 326 | + err := Call(context.Background(), "2", []string{}, false, []string{}) |
| 327 | + require.Error(t, err) |
| 328 | + assert.Equal(t, "no tool name provided", err.Error()) |
| 329 | +} |
| 330 | + |
| 331 | +func TestToText(t *testing.T) { |
| 332 | + // Test basic functionality - joining multiple text contents |
| 333 | + response := &mcp.CallToolResult{ |
| 334 | + Content: []mcp.Content{ |
| 335 | + &mcp.TextContent{Text: "First"}, |
| 336 | + &mcp.TextContent{Text: "Second"}, |
| 337 | + }, |
| 338 | + } |
| 339 | + result := toText(response) |
| 340 | + assert.Equal(t, "First\nSecond", result) |
| 341 | +} |
| 342 | + |
| 343 | +func TestParseArgs(t *testing.T) { |
| 344 | + // Test key=value parsing |
| 345 | + result := parseArgs([]string{"key1=value1", "key2=value2"}) |
| 346 | + expected := map[string]any{"key1": "value1", "key2": "value2"} |
| 347 | + assert.Equal(t, expected, result) |
| 348 | + |
| 349 | + // Test duplicate keys become arrays |
| 350 | + result = parseArgs([]string{"tag=red", "tag=blue"}) |
| 351 | + expected = map[string]any{"tag": []any{"red", "blue"}} |
| 352 | + assert.Equal(t, expected, result) |
| 353 | +} |
| 354 | + |
| 355 | +func TestToolDescription(t *testing.T) { |
| 356 | + // Test that title annotation takes precedence over description |
| 357 | + tool := &mcp.Tool{ |
| 358 | + Description: "Longer description", |
| 359 | + Annotations: &mcp.ToolAnnotations{Title: "Short Title"}, |
| 360 | + } |
| 361 | + result := toolDescription(tool) |
| 362 | + assert.Equal(t, "Short Title", result) |
| 363 | +} |
| 364 | + |
| 365 | +func TestDescriptionSummary(t *testing.T) { |
| 366 | + // Test key behavior: stops at first sentence |
| 367 | + result := descriptionSummary("First sentence. Second sentence.") |
| 368 | + assert.Equal(t, "First sentence.", result) |
| 369 | + |
| 370 | + // Test key behavior: stops at "Error Responses:" |
| 371 | + result = descriptionSummary("Tool description.\nError Responses:\n- 404 if not found") |
| 372 | + assert.Equal(t, "Tool description.", result) |
| 373 | +} |
0 commit comments