11package chi
22
33import (
4+ "bytes"
45 "context"
56 _ "embed"
7+ "encoding/json"
68 "errors"
79 "io"
810 "net/http"
@@ -15,7 +17,6 @@ import (
1517 "github.com/getkin/kin-openapi/openapi3"
1618 "github.com/getkin/kin-openapi/openapi3filter"
1719 "github.com/go-chi/chi/v5"
18- "github.com/oapi-codegen/testutil"
1920 "github.com/stretchr/testify/assert"
2021 "github.com/stretchr/testify/require"
2122)
@@ -29,8 +30,16 @@ func doGet(t *testing.T, mux http.Handler, rawURL string) *httptest.ResponseReco
2930 t .Fatalf ("Invalid url: %s" , rawURL )
3031 }
3132
32- response := testutil .NewRequest ().Get (u .RequestURI ()).WithHost (u .Host ).WithAcceptJson ().GoWithHTTPHandler (t , mux )
33- return response .Recorder
33+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
34+ require .NoError (t , err )
35+
36+ req .Header .Set ("accept" , "application/json" )
37+
38+ rr := httptest .NewRecorder ()
39+
40+ mux .ServeHTTP (rr , req )
41+
42+ return rr
3443}
3544
3645func doPost (t * testing.T , mux http.Handler , rawURL string , jsonBody interface {}) * httptest.ResponseRecorder {
@@ -39,8 +48,19 @@ func doPost(t *testing.T, mux http.Handler, rawURL string, jsonBody interface{})
3948 t .Fatalf ("Invalid url: %s" , rawURL )
4049 }
4150
42- response := testutil .NewRequest ().Post (u .RequestURI ()).WithHost (u .Host ).WithJsonBody (jsonBody ).GoWithHTTPHandler (t , mux )
43- return response .Recorder
51+ data , err := json .Marshal (jsonBody )
52+ require .NoError (t , err )
53+
54+ req , err := http .NewRequest (http .MethodGet , u .String (), bytes .NewReader (data ))
55+ require .NoError (t , err )
56+
57+ req .Header .Set ("content-type" , "application/json" )
58+
59+ rr := httptest .NewRecorder ()
60+
61+ mux .ServeHTTP (rr , req )
62+
63+ return rr
4464}
4565
4666func TestOapiRequestValidator (t * testing.T ) {
0 commit comments