MCPcopy Index your code
hub / github.com/docker/docker-agent / TestAPITool_POST

Function TestAPITool_POST

pkg/tools/builtin/api/api_test.go:88–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestAPITool_POST(t *testing.T) {
89 t.Parallel()
90 ts := getTestServer(t)
91
92 tool := newAPIToolForTest(latest.APIToolConfig{
93 Method: http.MethodPost,
94 Endpoint: ts.serverURL,
95 }, testExpander())
96
97 result, err := tool.callTool(t.Context(), tools.ToolCall{
98 Function: tools.FunctionCall{
99 Arguments: `{"name":"John Doe","age":30}`,
100 },
101 })
102
103 require.NoError(t, err)
104 assert.JSONEq(t, `{"status":"ok"}`, result.Output)
105 assert.Equal(t, http.MethodPost, ts.receivedMethod)
106 assert.Equal(t, "application/json", ts.receivedHeaders.Get("Content-Type"))
107
108 var receivedData map[string]any
109 err = json.Unmarshal(ts.receivedBody, &receivedData)
110 require.NoError(t, err)
111 assert.Equal(t, "John Doe", receivedData["name"])
112 assert.InEpsilon(t, 30.0, receivedData["age"], 0.01)
113}
114
115func TestAPITool_Headers(t *testing.T) {
116 t.Parallel()

Callers

nothing calls this directly

Calls 6

getTestServerFunction · 0.85
newAPIToolForTestFunction · 0.85
testExpanderFunction · 0.85
ContextMethod · 0.80
GetMethod · 0.65
callToolMethod · 0.45

Tested by

no test coverage detected