1515package echomiddleware
1616
1717import (
18+ "bytes"
1819 "context"
1920 _ "embed"
21+ "encoding/json"
2022 "errors"
2123 "io"
2224 "net/http"
2325 "net/http/httptest"
2426 "net/url"
2527 "testing"
2628
27- "github.com/deepmap/oapi-codegen/pkg/testutil"
2829 "github.com/getkin/kin-openapi/openapi3"
2930 "github.com/getkin/kin-openapi/openapi3filter"
3031 "github.com/labstack/echo/v4"
@@ -42,8 +43,18 @@ func doGet(t *testing.T, e *echo.Echo, rawURL string) *httptest.ResponseRecorder
4243 t .Fatalf ("Invalid url: %s" , rawURL )
4344 }
4445
45- response := testutil .NewRequest ().Get (u .RequestURI ()).WithHost (u .Host ).WithAcceptJson ().GoWithHTTPHandler (t , e )
46- return response .Recorder
46+ r , err := http .NewRequest (http .MethodGet , u .String (), nil )
47+ if err != nil {
48+ t .Fatalf ("Could not construct a request: %s" , rawURL )
49+ }
50+ r .Header .Set ("accept" , "application/json" )
51+ r .Header .Set ("host" , u .Host )
52+
53+ tt := httptest .NewRecorder ()
54+
55+ e .ServeHTTP (tt , r )
56+
57+ return tt
4758}
4859
4960func doPost (t * testing.T , e * echo.Echo , rawURL string , jsonBody interface {}) * httptest.ResponseRecorder {
@@ -52,8 +63,24 @@ func doPost(t *testing.T, e *echo.Echo, rawURL string, jsonBody interface{}) *ht
5263 t .Fatalf ("Invalid url: %s" , rawURL )
5364 }
5465
55- response := testutil .NewRequest ().Post (u .RequestURI ()).WithHost (u .Host ).WithJsonBody (jsonBody ).GoWithHTTPHandler (t , e )
56- return response .Recorder
66+ body , err := json .Marshal (jsonBody )
67+ if err != nil {
68+ t .Fatalf ("Could not marshal request body: %v" , err )
69+ }
70+
71+ r , err := http .NewRequest (http .MethodPost , u .String (), bytes .NewReader (body ))
72+ if err != nil {
73+ t .Fatalf ("Could not construct a request for URL %s: %v" , rawURL , err )
74+ }
75+ r .Header .Set ("accept" , "application/json" )
76+ r .Header .Set ("content-type" , "application/json" )
77+ r .Header .Set ("host" , u .Host )
78+
79+ tt := httptest .NewRecorder ()
80+
81+ e .ServeHTTP (tt , r )
82+
83+ return tt
5784}
5885
5986func TestOapiRequestValidator (t * testing.T ) {
0 commit comments