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

Function TestOpenAPITool_CallGET

pkg/tools/builtin/openapi/openapi_test.go:171–210  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

169}
170
171func TestOpenAPITool_CallGET(t *testing.T) {
172 t.Parallel()
173
174 var receivedURL string
175 apiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
176 receivedURL = r.URL.String()
177 w.Header().Set("Content-Type", "application/json")
178 _, _ = w.Write([]byte(`[{"id":1,"name":"Fido"}]`))
179 }))
180 t.Cleanup(apiServer.Close)
181
182 spec := `{
183 "openapi": "3.0.0",
184 "info": { "title": "Test", "version": "1.0.0" },
185 "servers": [{"url": "` + apiServer.URL + `"}],
186 "paths": {
187 "/pets": {
188 "get": {
189 "operationId": "listPets",
190 "summary": "List pets",
191 "parameters": [
192 {"name": "limit", "in": "query", "schema": {"type": "integer"}}
193 ],
194 "responses": { "200": {"description": "ok"} }
195 }
196 }
197 }
198 }`
199
200 specServer := serveSpec(t, spec)
201 toolsList, err := newOpenAPIToolForTest(specServer.URL+"/openapi.json", nil).Tools(t.Context())
202 require.NoError(t, err)
203 require.Len(t, toolsList, 1)
204
205 result := callTool(t, toolsList[0], `{"limit": 10}`)
206
207 assert.False(t, result.IsError)
208 assert.JSONEq(t, `[{"id":1,"name":"Fido"}]`, result.Output)
209 assert.Equal(t, "/pets?limit=10", receivedURL)
210}
211
212func TestOpenAPITool_CallPOST(t *testing.T) {
213 t.Parallel()

Callers

nothing calls this directly

Calls 10

serveSpecFunction · 0.85
newOpenAPIToolForTestFunction · 0.85
ContextMethod · 0.80
callToolFunction · 0.70
CleanupMethod · 0.65
ToolsMethod · 0.65
LenMethod · 0.65
StringMethod · 0.45
SetMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected