-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathcall_test.go
More file actions
137 lines (130 loc) · 2.83 KB
/
call_test.go
File metadata and controls
137 lines (130 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package tools
import (
"context"
"testing"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCallNoToolName(t *testing.T) {
err := Call(context.Background(), "2", []string{}, false, []string{})
require.Error(t, err)
assert.Equal(t, "no tool name provided", err.Error())
}
func TestParseArgs(t *testing.T) {
tests := []struct {
name string
args []string
expected map[string]any
}{
{
name: "empty args",
args: []string{},
expected: map[string]any{},
},
{
name: "simple key-value pairs",
args: []string{"key1=value1", "key2=value2"},
expected: map[string]any{
"key1": "value1",
"key2": "value2",
},
},
{
name: "key without value",
args: []string{"flag1", "key2=value2"},
expected: map[string]any{
"flag1": nil,
"key2": "value2",
},
},
{
name: "duplicate keys create array",
args: []string{"tag=red", "tag=blue", "tag=green"},
expected: map[string]any{
"tag": []any{"red", "blue", "green"},
},
},
{
name: "values with equals signs",
args: []string{"url=https://example.com/path?param=value"},
expected: map[string]any{
"url": "https://example.com/path?param=value",
},
},
{
name: "empty values",
args: []string{"empty=", "key=value"},
expected: map[string]any{
"empty": "",
"key": "value",
},
},
{
name: "mixed duplicate and single keys",
args: []string{"name=john", "tag=red", "tag=blue", "age=30"},
expected: map[string]any{
"name": "john",
"tag": []any{"red", "blue"},
"age": "30",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := parseArgs(tt.args)
assert.Equal(t, tt.expected, result)
})
}
}
func TestToText(t *testing.T) {
tests := []struct {
name string
response *mcp.CallToolResult
expected string
}{
{
name: "single text content",
response: &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: "Hello world"},
},
},
expected: "Hello world",
},
{
name: "multiple text contents",
response: &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: "First line"},
&mcp.TextContent{Text: "Second line"},
},
},
expected: "First line\nSecond line",
},
{
name: "empty content",
response: &mcp.CallToolResult{
Content: []mcp.Content{},
},
expected: "",
},
{
name: "nil content",
response: &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{Text: "Before nil"},
nil,
&mcp.TextContent{Text: "After nil"},
},
},
expected: "Before nil\n<nil>\nAfter nil",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := toText(tt.response)
assert.Equal(t, tt.expected, result)
})
}
}