MCPcopy
hub / github.com/danielgtaylor/huma / testAdapter

Function testAdapter

adapters/adapters_test.go:60–90  ·  view source on GitHub ↗
(t *testing.T, api huma.API)

Source from the content-addressed store, hash-verified

58}
59
60func testAdapter(t *testing.T, api huma.API) {
61 t.Helper()
62
63 methods := []string{http.MethodPut, http.MethodPost}
64
65 // Test two operations with the same path but different methods
66 for _, method := range methods {
67 huma.Register(api, huma.Operation{
68 OperationID: method + "-test",
69 Method: method,
70 Path: "/{group}",
71 }, testHandler)
72 }
73
74 // Make test calls
75 for _, method := range methods {
76 testAPI := humatest.Wrap(t, api)
77 resp := testAPI.Do(method, "/foo",
78 "Host: localhost",
79 "Authorization: Bearer abc123",
80 strings.NewReader(`{"name": "Daniel", "email": "daniel@example.com"}`),
81 )
82
83 assert.Equal(t, http.StatusOK, resp.Code)
84 assert.Equal(t, "my-value", resp.Header().Get("MyHeader"))
85 assert.JSONEq(t, `{
86 "$schema": "http://localhost/schemas/TestOutputBody.json",
87 "message": "Hello, Daniel <daniel@example.com>! (foo, false, Bearer abc123)"
88 }`, resp.Body.String())
89 }
90}
91
92func TestAdapters(t *testing.T) {
93 config := func() huma.Config {

Callers 1

TestAdaptersFunction · 0.85

Calls 6

WrapFunction · 0.92
HelperMethod · 0.80
DoMethod · 0.65
GetMethod · 0.65
HeaderMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…