Skip to content

Commit d6b56f6

Browse files
committed
Adding coverage to tools package
1 parent f592a22 commit d6b56f6

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ make format
2323
make lint
2424
```
2525

26+
## Testing
27+
28+
### Running Tests
29+
30+
```bash
31+
# Run all unit tests
32+
make test
33+
34+
# Run integration tests (requires Docker plugin to be installed)
35+
make integration
36+
```
37+
38+
### Unit Test Coverage
39+
40+
```bash
41+
# Generate HTML coverage report for ALL packages in one view
42+
go test -cover -coverprofile=coverage.out ./... -short
43+
go tool cover -html=coverage.out -o coverage.html && open coverage.html
44+
```
45+
2646
## Open a Pull Request
2747

2848
1. Fork the repository

cmd/docker-mcp/tools/call_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/modelcontextprotocol/go-sdk/mcp"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestCallNoToolName(t *testing.T) {
13+
err := Call(context.Background(), "2", []string{}, false, []string{})
14+
require.Error(t, err)
15+
assert.Equal(t, "no tool name provided", err.Error())
16+
}
17+
18+
func TestToText(t *testing.T) {
19+
// Test basic functionality - joining multiple text contents
20+
response := &mcp.CallToolResult{
21+
Content: []mcp.Content{
22+
&mcp.TextContent{Text: "First"},
23+
&mcp.TextContent{Text: "Second"},
24+
},
25+
}
26+
result := toText(response)
27+
assert.Equal(t, "First\nSecond", result)
28+
}
29+
30+
func TestParseArgs(t *testing.T) {
31+
// Test key=value parsing
32+
result := parseArgs([]string{"key1=value1", "key2=value2"})
33+
expected := map[string]any{"key1": "value1", "key2": "value2"}
34+
assert.Equal(t, expected, result)
35+
36+
// Test duplicate keys become arrays
37+
result = parseArgs([]string{"tag=red", "tag=blue"})
38+
expected = map[string]any{"tag": []any{"red", "blue"}}
39+
assert.Equal(t, expected, result)
40+
}

cmd/docker-mcp/tools/list_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tools
2+
3+
import (
4+
"testing"
5+
6+
"github.com/modelcontextprotocol/go-sdk/mcp"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestToolDescription(t *testing.T) {
11+
// Test that title annotation takes precedence over description
12+
tool := &mcp.Tool{
13+
Description: "Longer description",
14+
Annotations: &mcp.ToolAnnotations{Title: "Short Title"},
15+
}
16+
result := toolDescription(tool)
17+
assert.Equal(t, "Short Title", result)
18+
}
19+
20+
func TestDescriptionSummary(t *testing.T) {
21+
// Test key behavior: stops at first sentence
22+
result := descriptionSummary("First sentence. Second sentence.")
23+
assert.Equal(t, "First sentence.", result)
24+
25+
// Test key behavior: stops at "Error Responses:"
26+
result = descriptionSummary("Tool description.\nError Responses:\n- 404 if not found")
27+
assert.Equal(t, "Tool description.", result)
28+
}

0 commit comments

Comments
 (0)