Skip to content

Commit 36776cf

Browse files
committed
Consolidate tools tests into tools test file
1 parent e4d0dcd commit 36776cf

File tree

3 files changed

+53
-68
lines changed

3 files changed

+53
-68
lines changed

cmd/docker-mcp/tools/call_test.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

cmd/docker-mcp/tools/list_test.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

cmd/docker-mcp/tools/enable_test.go renamed to cmd/docker-mcp/tools/tools_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/docker/docker/api/types/volume"
11+
"github.com/modelcontextprotocol/go-sdk/mcp"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314

@@ -318,3 +319,55 @@ func withSampleCatalog() option {
318319
writeFile(t, filepath.Join(home, ".docker/mcp/catalogs/docker-mcp.yaml"), []byte(catalogContent))
319320
}
320321
}
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

Comments
 (0)