| 58 | } |
| 59 | |
| 60 | func 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 | |
| 92 | func TestAdapters(t *testing.T) { |
| 93 | config := func() huma.Config { |